Skip to content

Commit aaf204c

Browse files
remove active camera entity when despawned (#1825)
fixes #1452 This should probably be in 0.5, as the previous workaround isn't possible after dd4a196 because the hashmap is now private.
1 parent 3118ebd commit aaf204c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/bevy_render/src/camera/active_cameras.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ impl ActiveCameras {
3838
self.cameras.get_mut(name)
3939
}
4040

41+
pub fn remove(&mut self, name: &str) -> Option<ActiveCamera> {
42+
self.cameras.remove(name)
43+
}
44+
4145
pub fn iter(&self) -> impl Iterator<Item = &ActiveCamera> {
4246
self.cameras.values()
4347
}
@@ -52,6 +56,13 @@ pub fn active_cameras_system(
5256
query: Query<(Entity, &Camera)>,
5357
) {
5458
for (name, active_camera) in active_cameras.cameras.iter_mut() {
59+
if active_camera
60+
.entity
61+
.map_or(false, |entity| query.get(entity).is_err())
62+
{
63+
active_camera.entity = None;
64+
}
65+
5566
if active_camera.entity.is_none() {
5667
for (camera_entity, camera) in query.iter() {
5768
if let Some(ref current_name) = camera.name {

0 commit comments

Comments
 (0)