From 6701ad25db23549cbfab18491d737c91538d43a5 Mon Sep 17 00:00:00 2001 From: Rob Parrett Date: Thu, 10 Oct 2024 20:13:33 -0700 Subject: [PATCH] Fix `loading_screen` example (#15845) # 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>") ``` 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` --- examples/games/loading_screen.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/games/loading_screen.rs b/examples/games/loading_screen.rs index 6ae7139b523ad..4e5967ad5426f 100644 --- a/examples/games/loading_screen.rs +++ b/examples/games/loading_screen.rs @@ -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>, + mut loading_screen: Query<&mut Visibility, (With, With)>, loading_state: Res, ) { - 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 {