diff --git a/crates/bevy_transform/src/commands.rs b/crates/bevy_transform/src/commands.rs index ec0ef0bc2e..bf3f257884 100644 --- a/crates/bevy_transform/src/commands.rs +++ b/crates/bevy_transform/src/commands.rs @@ -2,7 +2,11 @@ //! while preserving [`GlobalTransform`]. use crate::prelude::{GlobalTransform, Transform}; -use bevy_ecs::{prelude::Entity, system::EntityCommands, world::Command, world::World}; +use bevy_ecs::{ + prelude::Entity, + system::EntityCommands, + world::{Command, EntityWorldMut, World}, +}; use bevy_hierarchy::{PushChild, RemoveParent}; /// Command similar to [`PushChild`], but updating the child transform to keep @@ -97,3 +101,17 @@ impl BuildChildrenTransformExt for EntityCommands<'_> { self } } + +impl BuildChildrenTransformExt for EntityWorldMut<'_> { + fn set_parent_in_place(&mut self, parent: Entity) -> &mut Self { + let child = self.id(); + self.world_scope(|world| PushChildInPlace { child, parent }.apply(world)); + self + } + + fn remove_parent_in_place(&mut self) -> &mut Self { + let child = self.id(); + self.world_scope(|world| RemoveParentInPlace { child }.apply(world)); + self + } +}