diff --git a/crates/bevy_ecs/src/world/deferred_world.rs b/crates/bevy_ecs/src/world/deferred_world.rs index 36b8176e3cb1a..05df7dc762380 100644 --- a/crates/bevy_ecs/src/world/deferred_world.rs +++ b/crates/bevy_ecs/src/world/deferred_world.rs @@ -75,11 +75,7 @@ impl<'w> DeferredWorld<'w> { &mut self, entity: Entity, ) -> Option> { - // SAFETY: - // - `as_unsafe_world_cell` is the only thing that is borrowing world - // - `as_unsafe_world_cell` provides mutable permission to everything - // - `&mut self` ensures no other borrows on world data - unsafe { self.world.get_entity(entity)?.get_mut() } + self.get_entity_mut(entity).ok()?.into_mut() } /// Temporarily removes a [`Component`] `T` from the provided [`Entity`] and @@ -491,13 +487,10 @@ impl<'w> DeferredWorld<'w> { entity: Entity, component_id: ComponentId, ) -> Option> { - // SAFETY: &mut self ensure that there are no outstanding accesses to the resource - unsafe { - self.world - .get_entity(entity)? - .get_mut_by_id(component_id) - .ok() - } + self.get_entity_mut(entity) + .ok()? + .into_mut_by_id(component_id) + .ok() } /// Triggers all `on_add` hooks for [`ComponentId`] in target. diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 16948c5a9f740..d0a439410f90c 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -1230,11 +1230,7 @@ impl World { &mut self, entity: Entity, ) -> Option> { - // SAFETY: - // - `as_unsafe_world_cell` is the only thing that is borrowing world - // - `as_unsafe_world_cell` provides mutable permission to everything - // - `&mut self` ensures no other borrows on world data - unsafe { self.as_unsafe_world_cell().get_entity(entity)?.get_mut() } + self.get_entity_mut(entity).ok()?.into_mut() } /// Temporarily removes a [`Component`] `T` from the provided [`Entity`] and @@ -3509,14 +3505,7 @@ impl World { /// This function will panic if it isn't called from the same thread that the resource was inserted from. #[inline] pub fn get_by_id(&self, entity: Entity, component_id: ComponentId) -> Option> { - // SAFETY: - // - `&self` ensures that all accessed data is not mutably aliased - // - `as_unsafe_world_cell_readonly` provides shared/readonly permission to the whole world - unsafe { - self.as_unsafe_world_cell_readonly() - .get_entity(entity)? - .get_by_id(component_id) - } + self.get_entity(entity).ok()?.get_by_id(component_id).ok() } /// Retrieves a mutable untyped reference to the given `entity`'s [`Component`] of the given [`ComponentId`]. @@ -3530,15 +3519,10 @@ impl World { entity: Entity, component_id: ComponentId, ) -> Option> { - // SAFETY: - // - `&mut self` ensures that all accessed data is unaliased - // - `as_unsafe_world_cell` provides mutable permission to the whole world - unsafe { - self.as_unsafe_world_cell() - .get_entity(entity)? - .get_mut_by_id(component_id) - .ok() - } + self.get_entity_mut(entity) + .ok()? + .into_mut_by_id(component_id) + .ok() } }