diff --git a/crates/bevy_hierarchy/src/child_builder.rs b/crates/bevy_hierarchy/src/child_builder.rs index a1ed4cf713..ba772d328d 100644 --- a/crates/bevy_hierarchy/src/child_builder.rs +++ b/crates/bevy_hierarchy/src/child_builder.rs @@ -584,6 +584,10 @@ impl BuildChildren for EntityWorldMut<'_> { } fn push_children(&mut self, children: &[Entity]) -> &mut Self { + if children.is_empty() { + return self; + } + let parent = self.id(); if children.contains(&parent) { panic!("Cannot push entity as a child of itself."); @@ -1214,4 +1218,14 @@ mod tests { let children = query.get(&world, parent).unwrap(); assert_eq!(**children, [child]); } + + #[test] + fn push_children_does_not_insert_empty_children() { + let mut world = World::new(); + let parent = world.spawn_empty().push_children(&[]).id(); + + let mut query = world.query::<&Children>(); + let children = query.get(&world, parent); + assert!(children.is_err()); + } }