From e552d8293f276e4c072288d1fda58f62e2426677 Mon Sep 17 00:00:00 2001 From: Christian Hughes Date: Mon, 4 Aug 2025 01:34:44 -0500 Subject: [PATCH] better withrelated ergonomics --- crates/bevy_ecs/src/spawn.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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();