I ran into an issue using Commands::spawn_batch to spawn in a bunch of entities that have some custom components and also needed a SpriteComponents bundle for rendering, and the only way I could find to do this was to use commands.spawn(...).with_bundle(...) or inline the fields of SpriteComponents. Both of these are sub-optimal solutions in my eyes.
One way to solve this would be to add a combinator for Bundle like
trait Bundle {
// ...
fn and<B: Bundle>(self, other: B) -> And<Self, B> where Self: Sized {
And { first: self, second: other }
}
}
struct And<A, B> {
first: A,
second: B,
}
impl<A: Bundle, B: Bundle> Bundle for And<A, B> {
// ...
}
such that
fn some_startup(mut commands: Commands) {
commands.spawn(bundle_a).with_bundle(bundle_b);
}
// has the same effect as
fn some_startup(mut commands: Commands) {
commands.spawn(bundle_a.and(bundle_b));
}
This would allow you to combine bundles in places where you can only pass in a single bundle, for example Commands::spawn_batch.
I ran into an issue using
Commands::spawn_batchto spawn in a bunch of entities that have some custom components and also needed aSpriteComponentsbundle for rendering, and the only way I could find to do this was to usecommands.spawn(...).with_bundle(...)or inline the fields ofSpriteComponents. Both of these are sub-optimal solutions in my eyes.One way to solve this would be to add a combinator for
Bundlelikesuch that
This would allow you to combine bundles in places where you can only pass in a single bundle, for example
Commands::spawn_batch.