remove active camera entity when despawned (#1825)

fixes #1452

This should probably be in 0.5, as the previous workaround isn't possible after dd4a196329 because the hashmap is now private.
This commit is contained in:
Jakob Hellermann 2021-04-06 17:09:28 +00:00
parent 3118ebdfd3
commit aaf204cbac

View File

@ -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()
}
@ -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 {