diff --git a/crates/bevy_transform/src/commands.rs b/crates/bevy_transform/src/commands.rs index f1d0541886..b73e5d1f48 100644 --- a/crates/bevy_transform/src/commands.rs +++ b/crates/bevy_transform/src/commands.rs @@ -46,13 +46,17 @@ impl BuildChildrenTransformExt for EntityWorldMut<'_> { fn set_parent_in_place(&mut self, parent: Entity) -> &mut Self { // FIXME: Replace this closure with a `try` block. See: https://github.com/rust-lang/rust/issues/31436. let mut update_transform = || { - let parent_global = self - .world() - .get_entity(parent) - .ok()? - .get::()?; + let child = self.id(); + let parent_global = self.world_scope(|world| { + world + .get_entity_mut(parent) + .ok()? + .add_child(child) + .get::() + .copied() + })?; let child_global = self.get::()?; - let new_child_local = child_global.reparented_to(parent_global); + let new_child_local = child_global.reparented_to(&parent_global); // TODO: Can this just be `self.insert(new_child_local)`? (does it matter if self doesn't already have `Transform`?) let mut child_local = self.get_mut::()?; *child_local = new_child_local;