-
I have a couple different plugins running in my game and I want to run a few setup systems on startup and others every frame. I don't know if the details matter but I am setting up a camera as a child of a Scene (which is the player's 3d character model). The main parts of the code I use are this: To load and setup the heirarchy: pub struct GameplayPlugin;
impl Plugin for GameplayPlugin {
fn build(&self, app: &mut App) {
app
.add_plugins((MovementPlugin, CameraPlugin))
.add_systems(PreStartup, player_asset_loader)
.add_systems(Startup, spawn_player)
.add_systems(PostStartup, setup_camera_child);
}
} To handle camera movement: pub struct CameraPlugin;
impl Plugin for CameraPlugin {
fn build(&self, app: &mut App) {
app
.add_systems(Update, change_camera)
.add_systems(Update, transition_camera.run_if(camera_is_transitioning));
}
} The main fn main() {
App::new()
.insert_resource(ClearColor(Color::rgb(0.2, 0.2, 0.2)))
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
title: "Obs game test".to_string(),
resizable: false,
// Turn off vsync to maximize CPU/GPU usage
present_mode: PresentMode::AutoVsync,
// present_mode: PresentMode::AutoNoVsync,
..default()
}),
..default()
}))
.add_plugins(WorldInspectorPlugin::new())
.add_plugins((GameplayPlugin, WorldPlugin))
.add_systems(Update, bevy::window::close_on_esc)
.run();
} However, I get this error: thread 'Compute Task Pool (0)' panicked at src/player_mechanics/camera.rs:163:22:
called `Result::unwrap()` on an `Err` value: NoEntities("bevy_ecs::query::state::QueryState<&obs_game::player_mechanics::camera::CameraSettings>")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in system `bevy_app::main_schedule::Main::run_main`! That comes from: fn camera_is_transitioning(q: Query<&CameraSettings>) -> bool {
let settings = q.single();
settings.target_view_state.is_some()
} This leads me to believe that the system scheduled for |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The line at fault is probably let settings = q.single(); can panic if you don't have spawned the Camera yet you can solve it by
let Ok(settings) = q.get_single() else {
return false;
}
// Your logic here |
Beta Was this translation helpful? Give feedback.
The line at fault is probably
can panic if you don't have spawned the Camera yet
you can solve it by