diff --git a/crates/bevy_ecs/src/spawn.rs b/crates/bevy_ecs/src/spawn.rs index cf4f8b6fee..f9bb94ea0e 100644 --- a/crates/bevy_ecs/src/spawn.rs +++ b/crates/bevy_ecs/src/spawn.rs @@ -2,11 +2,12 @@ //! for the best entry points into these APIs and examples of how to use them. use crate::{ - bundle::{Bundle, BundleEffect, DynamicBundle}, + bundle::{Bundle, BundleEffect, DynamicBundle, NoBundleEffect}, entity::Entity, relationship::{RelatedSpawner, Relationship, RelationshipTarget}, world::{EntityWorldMut, World}, }; +use alloc::vec::Vec; use core::marker::PhantomData; use variadics_please::all_tuples; @@ -45,6 +46,17 @@ pub trait SpawnableList { fn size_hint(&self) -> usize; } +impl> SpawnableList for Vec { + fn spawn(self, world: &mut World, entity: Entity) { + let mapped_bundles = self.into_iter().map(|b| (R::from(entity), b)); + world.spawn_batch(mapped_bundles); + } + + fn size_hint(&self) -> usize { + self.len() + } +} + impl SpawnableList for Spawn { fn spawn(self, world: &mut World, entity: Entity) { world.spawn((R::from(entity), self.0)); diff --git a/examples/tools/scene_viewer/morph_viewer_plugin.rs b/examples/tools/scene_viewer/morph_viewer_plugin.rs index b217c40b74..90cb7ef838 100644 --- a/examples/tools/scene_viewer/morph_viewer_plugin.rs +++ b/examples/tools/scene_viewer/morph_viewer_plugin.rs @@ -273,21 +273,16 @@ fn detect_morphs( |(i, target): (usize, &Target)| target.text_span(AVAILABLE_KEYS[i].name, style.clone()); spans.extend(detected.iter().enumerate().map(target_to_text)); commands.insert_resource(WeightsControl { weights: detected }); - commands - .spawn(( - Text::default(), - Node { - position_type: PositionType::Absolute, - top: Val::Px(12.0), - left: Val::Px(12.0), - ..default() - }, - )) - .with_children(|p| { - for span in spans { - p.spawn(span); - } - }); + commands.spawn(( + Text::default(), + Node { + position_type: PositionType::Absolute, + top: Val::Px(12.0), + left: Val::Px(12.0), + ..default() + }, + Children::spawn(spans), + )); } pub struct MorphViewerPlugin;