diff --git a/crates/bevy_ecs/src/spawn.rs b/crates/bevy_ecs/src/spawn.rs index df608829740aa..bafd8c6ad0246 100644 --- a/crates/bevy_ecs/src/spawn.rs +++ b/crates/bevy_ecs/src/spawn.rs @@ -153,12 +153,19 @@ impl) + Send + Sync + 'static> /// Children::spawn(( /// Spawn(Name::new("Child1")), /// // This adds the already existing entities as children of Root. -/// WithRelated([child2, child3].into_iter()), +/// WithRelated::new([child2, child3]), /// )), /// )); /// ``` pub struct WithRelated(pub I); +impl WithRelated { + /// Creates a new [`WithRelated`] from a collection of entities. + pub fn new(iter: impl IntoIterator) -> Self { + Self(iter.into_iter()) + } +} + impl> SpawnableList for WithRelated { fn spawn(self, world: &mut World, entity: Entity) { world @@ -653,7 +660,7 @@ mod tests { let parent = world .spawn(( Name::new("Parent"), - Children::spawn(WithRelated([child1, child2].into_iter())), + Children::spawn(WithRelated::new([child1, child2])), )) .id();