Skip to content

Commit

Permalink
Fix loading_screen example (#15845)
Browse files Browse the repository at this point in the history
# Objective

Since #15641, `loading_screen` panics.

```
called `Result::unwrap()` on an `Err` value: MultipleEntities("bevy_ecs::query::state::QueryState<&mut bevy_render::view::visibility::Visibility, bevy_ecs::query::filter::With<loading_screen::LoadingScreen>>")
```

Before that PR, the camera did not have a `Visibility` component. But
`Visibility` is now a required component of `Camera`. So the query
matches multiple entities.

## Solution

Minimal change to make the example behave like it used to.

Plus a tiny drive-by cleanup to remove a redundant unwrap.

## Testing

`cargo run --example loading_screen`
  • Loading branch information
rparrett authored Oct 11, 2024
1 parent ae0b718 commit 6701ad2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions examples/games/loading_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,15 @@ fn load_loading_screen(mut commands: Commands) {

// Determines when to show the loading screen
fn display_loading_screen(
mut loading_screen: Query<&mut Visibility, With<LoadingScreen>>,
mut loading_screen: Query<&mut Visibility, (With<LoadingScreen>, With<Node>)>,
loading_state: Res<LoadingState>,
) {
match loading_state.as_ref() {
LoadingState::LevelLoading => {
*loading_screen.get_single_mut().unwrap() = Visibility::Visible;
}
LoadingState::LevelReady => *loading_screen.get_single_mut().unwrap() = Visibility::Hidden,
let visibility = match loading_state.as_ref() {
LoadingState::LevelLoading => Visibility::Visible,
LoadingState::LevelReady => Visibility::Hidden,
};

*loading_screen.single_mut() = visibility;
}

mod pipelines_ready {
Expand Down

0 comments on commit 6701ad2

Please sign in to comment.