diff --git a/crates/bevy_hierarchy/src/child_builder.rs b/crates/bevy_hierarchy/src/child_builder.rs index 6c32979666..dc63df1679 100644 --- a/crates/bevy_hierarchy/src/child_builder.rs +++ b/crates/bevy_hierarchy/src/child_builder.rs @@ -612,6 +612,10 @@ impl<'w> BuildWorldChildren for EntityWorldMut<'w> { } 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."); @@ -1242,4 +1246,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()); + } }