diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index 7d1051bba19889..2b6314536c6ef4 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -495,15 +495,25 @@ impl<'w> EntityMut<'w> { self.world } + /// Returns this `EntityMut`'s world. + /// + /// See [`EntityMut::into_world_mut`] for a safe alternative. + /// /// # Safety /// Caller must not modify the world in a way that changes the current entity's location /// If the caller _does_ do something that could change the location, `self.update_location()` - /// must be called before using any other methods in [`EntityMut`] + /// must be called before using any other methods on this [`EntityMut`]. #[inline] pub unsafe fn world_mut(&mut self) -> &mut World { self.world } + /// Return this `EntityMut`'s [`World`], consuming itself. + #[inline] + pub fn into_world_mut(self) -> &'w mut World { + self.world + } + /// Updates the internal entity location to match the current location in the internal /// [`World`]. This is only needed if the user called [`EntityMut::world`], which enables the /// location to change.