diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index 72f5d59113..e047ead152 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -82,6 +82,12 @@ impl<'w> EntityRef<'w> { self.cell.location() } + /// Returns if the entity is constructed or not. + #[inline] + pub fn is_constructed(&self) -> bool { + self.cell.location().is_some() + } + /// Returns the archetype that the current entity belongs to. #[inline] pub fn archetype(&self) -> Option<&Archetype> { @@ -492,6 +498,12 @@ impl<'w> EntityMut<'w> { self.cell.location() } + /// Returns if the entity is constructed or not. + #[inline] + pub fn is_constructed(&self) -> bool { + self.cell.location().is_some() + } + /// Returns the archetype that the current entity belongs to. #[inline] pub fn archetype(&self) -> Option<&Archetype> { @@ -1220,7 +1232,7 @@ impl<'w> EntityWorldMut<'w> { } } - /// Returns whether or not the entity is constructed. + /// Returns if the entity is constructed or not. #[inline] pub fn is_constructed(&self) -> bool { self.location.is_some() @@ -3277,6 +3289,12 @@ impl<'w> FilteredEntityRef<'w> { self.entity.location() } + /// Returns if the entity is constructed or not. + #[inline] + pub fn is_constructed(&self) -> bool { + self.entity.location().is_some() + } + /// Returns the archetype that the current entity belongs to. #[inline] pub fn archetype(&self) -> Option<&Archetype> { @@ -3619,6 +3637,12 @@ impl<'w> FilteredEntityMut<'w> { self.entity.location() } + /// Returns if the entity is constructed or not. + #[inline] + pub fn is_constructed(&self) -> bool { + self.entity.location().is_some() + } + /// Returns the archetype that the current entity belongs to. #[inline] pub fn archetype(&self) -> Option<&Archetype> { diff --git a/crates/bevy_scene/src/serde.rs b/crates/bevy_scene/src/serde.rs index cb8206d3dd..6c940839d0 100644 --- a/crates/bevy_scene/src/serde.rs +++ b/crates/bevy_scene/src/serde.rs @@ -774,7 +774,10 @@ mod tests { assert!(dst_world .query_filtered::<&MyEntityRef, With>() .iter(&dst_world) - .all(|r| world.get_entity(r.0).is_err())); + .all(|r| world + .get_entity(r.0) + .map(|entity| !entity.is_constructed()) + .unwrap_or(true))); } #[test]