Skip to content

Commit fef6b51

Browse files
authored
FreeCam: stop cursor from remaining grabbed when camera controller is disabled (#21485)
# Objective Fixes #21482 ## Solution Before exiting the system when the controller is disabled, check if either of the cursor grab flags are set and ungrab any windows if so. Note: I think it's a bit strange that the camera un-grabs every window, not just the one with focus, but I've just copied this behaviour from further down in the function. In this case, it might be more correct to do this anyway, since the controller might be disabled when the respective window isn't focused. ## Testing I used #21477 to test this
1 parent f3ec3c0 commit fef6b51

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/bevy_camera_controller/src/free_cam.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,18 @@ pub fn run_freecam_controller(
182182
controller.initialized = true;
183183
info!("{}", *controller);
184184
}
185+
185186
if !controller.enabled {
187+
// don't keep the cursor grabbed if the controller was disabled.
188+
if *toggle_cursor_grab || *mouse_cursor_grab {
189+
*toggle_cursor_grab = false;
190+
*mouse_cursor_grab = false;
191+
192+
for (_, mut cursor_options) in &mut windows {
193+
cursor_options.grab_mode = CursorGrabMode::None;
194+
cursor_options.visible = true;
195+
}
196+
}
186197
return;
187198
}
188199

0 commit comments

Comments
 (0)