Skip to content

Merge bundles together #792

@RustyYato

Description

@RustyYato

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to useS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions