Skip to content

Commit 89193cc

Browse files
Fix empty children regression (#21099)
## Objective #18865 introduced a regression for an empty invocation of `children!` and `related!`. The `recursive_spawn` macro has no case for zero inputs, so the compiler rejects `children![]`. Whether this is particularly meaningful isn't important; there are a number of situations in which you might want your code to compile even with an empty set of children. ## Solution A case has been added to `recursive_spawn` for no inputs, returning a unit. This matches the previous behavior for `children!` and `related!` exactly.
1 parent 3dd5dc6 commit 89193cc

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

crates/bevy_ecs/src/hierarchy.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,9 @@ mod tests {
808808
fn spawn_many_children() {
809809
let mut world = World::new();
810810

811+
// ensure an empty set can be mentioned
812+
world.spawn(children![]);
813+
811814
// 12 children should result in a flat tuple
812815
let id = world
813816
.spawn(children![(), (), (), (), (), (), (), (), (), (), (), ()])

crates/bevy_ecs/src/spawn.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ macro_rules! related {
513513
#[doc(hidden)]
514514
macro_rules! recursive_spawn {
515515
// direct expansion
516+
() => { () };
516517
($a:expr) => {
517518
$crate::spawn::Spawn($a)
518519
};

0 commit comments

Comments
 (0)