Open franklinblanco opened 5 months ago
I just clicked an entity in the editor and pressed F. That is the error. Cargo.toml
bevy = { version = "0.13.1" }
bevy_editor_pls = "0.8"
Hm, I can't reproduce, for me it works fine. From the panic it looks like there is no ActiveEditorCamera
but I don't know how that can happen :/
Older versions have this issue as well, e.g. bevy = { version = "0.12.1", features = ["bevy_winit"] } bevy_editor_pls = "0.7.0"
I've got a multiwindow setup like so:
fn setup_editor_window() -> EditorPlugin {
EditorPlugin::
in_new_window(Default::default(), Window {
title: EDITOR_WINDOW_NAME.to_string(),
mode: WindowMode::Windowed,
position: WindowPosition::Centered(MonitorSelection::Index(1)),
..Default::default()
})
}
WTR:
If I manually select different camera mode, and then switch back - it does not panic.
Ended up forking repo and modifying cameras.mod @ 444 like so:
let Ok((mut camera_tf, pan_orbit_cam, ortho)) = active_cam.get_single_mut() else {
let camera_count = active_cam.iter().count();
info!("Cannot focus. Select camera first. Total active cameras: {:?}", camera_count);
return;
};
Active camera count is indeed zero for some reason. Editor should not panic / shutdown whole editor + application for this case anyway. Notifying user should be enough.
As an alternative fix - perhaps introduce some kind of active camera settings into the plugin? So that specific active camera could be applied during application initialization. Exposing somehow access to the active camera state from code would be nice.
Ended up with this solution:
impl CameraWindowState {
/// Sets current active editor camera to the specified `EditorCamKind`
pub fn set_active_camera(&mut self, camera: EditorCamKind, world: &mut World)
{
// This should be identitical to viewport_toolbar_ui internal logic (on button click)
if self.editor_cam != camera {
set_active_editor_camera_marker(world, camera);
}
self.editor_cam = camera;
}
}
Then in a separate system after initialization:
pub fn switch_to_2d_camera(
world: &mut World,
) {
...
world.resource_scope(|world, mut editor: Mut<Editor>| {
let Some(camera_window_state) = editor.window_state_mut::<CameraWindow>() else {
return;
};
camera_window_state.set_active_camera(EditorCamKind::D2PanZoom, world);
info!("Switched to 2d camera");
});
...
}
This works and switches camera to the proper state on application start. Though requires a separate system to do so.