Skip to content

Bundles with optional components #2157

Open
@botiapa

Description

@botiapa

What problem does this solve or what need does it fill?

Currently if a bundle has components which are wrapped in an Option<>, they are treated literally. However in my opinion it would be a good addition if we had the option to mark optional components, and they would be treated as such.

What solution would you like?

Unfortunately I don't understand the inner workings of bevy enough to propose an exact solution, but after having a small conversation on discord, it has come to my attention, that there had been a similar feature like this in the old ECS called DynamicBundle. An example might look like this:

#[derive(Bundle)]
struct BundleA {
    component_a: f32,
    #[optional]
    component_b: Option<i32>
}

// In a system
let bundle = BundleA { component_a: 0f32, component_b: None };
commands.spawn_bundle(bundle) // --> Only component_a is added to the entity;

What alternative(s) have you considered?

Manually checking every optional component and adding it manually.

Additional context

I hadn't used DynamicBundle when it was still in, so I don't know if what I'm proposing makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleD-ComplexQuite challenging from either a design or technical perspective. Ask for help!S-Needs-Design-DocThis issue or PR is particularly complex, and needs an approved design doc before it can be merged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions