From 86be404caf6c43caab319109c71784ed838098e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Harabie=C5=84?= Date: Wed, 16 Oct 2024 13:07:18 +0200 Subject: [PATCH] Fix deactivated camera still being used in render world Switch to retained render world causes the extracted cameras in render world to not be removed until camera in main world is despawned. When extracting data from main world inactive cameras are skipped. Therefore camera that was active and became inactive has a retained `ExtractedCamera` component from previous frames (when it was active) and is processed the same way as if it were active (there is no `active` field on `ExtractedCamera`). This breakes switching between cameras in `render_primitives` example. Fix it by removing `ExtractedCamera` and related components from inactive cameras. Note that despawning inactive camera seems to be bad option because they are spawned using `SyncToRenderWorld` component. Fixes #15822 --- crates/bevy_render/src/camera/camera.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index dfd395ed7916d..5bf8350918568 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -1054,8 +1054,14 @@ pub fn extract_cameras( ) in query.iter() { if !camera.is_active { + commands + .entity(render_entity) + .remove::() + .remove::() + .remove::(); continue; } + let color_grading = color_grading.unwrap_or(&ColorGrading::default()).clone(); if let (