Skip to content

Commit

Permalink
remove active camera entity when despawned (#1825)
Browse files Browse the repository at this point in the history
fixes #1452

This should probably be in 0.5, as the previous workaround isn't possible after dd4a196 because the hashmap is now private.
  • Loading branch information
jakobhellermann committed Apr 6, 2021
1 parent 3118ebd commit aaf204c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/bevy_render/src/camera/active_cameras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ impl ActiveCameras {
self.cameras.get_mut(name)
}

pub fn remove(&mut self, name: &str) -> Option<ActiveCamera> {
self.cameras.remove(name)
}

pub fn iter(&self) -> impl Iterator<Item = &ActiveCamera> {
self.cameras.values()
}
Expand All @@ -52,6 +56,13 @@ pub fn active_cameras_system(
query: Query<(Entity, &Camera)>,
) {
for (name, active_camera) in active_cameras.cameras.iter_mut() {
if active_camera
.entity
.map_or(false, |entity| query.get(entity).is_err())
{
active_camera.entity = None;
}

if active_camera.entity.is_none() {
for (camera_entity, camera) in query.iter() {
if let Some(ref current_name) = camera.name {
Expand Down

0 comments on commit aaf204c

Please sign in to comment.