Bundles with optional components
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
## 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:
```rust
#[derive(Bundle)]
struct BundleA {
component_a: f32,
#[optional]
component_b: Option
}
// 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.
Contributor guide
Assessment
This issue has not been assessed yet.