bevyengine / bevyengine/bevy

Better tools for working with dynamic collections of components

Open
#3,227 23 comments 13 reactions 0 assignees View on GitHub
A-ECS C-Usability S-Needs-Design
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?

Working with dynamic collections of components (as might be used in advanced spawning patterns) is very painful at the moment: every straightforward path is blocked due to missing impls. This cannot be fixed in end user code, as they do not own the `Component` trait, or the common wrapper types like `Vec` and `Box`.

## What solution would you like?

1. Implement `Component` for `Box`, which uses the box's data as the component.
2. Do similarly for `Rc` and `Arc` (and any other common smart pointers).
3. Implement `Bundle` for `IntoIter`, which combined with the above would allow us to use structs like `Vec>` as bundles.

Notes:
1. This will need to be done for each of the standard storage types, as we cannot vary the associated type found within the trait object.
2. In practice, we may need `DynClone` for this pattern to actually work, which would probably force a `DynComponent` trait layer.

## What alternative(s) have you considered?

Other possible approaches:
- make `Bundle` itself object-safe, obviating 3. I don't think this will be feasible.
- implement `Component` for `&Component`, since we can get these out of our boxes. This doesn't work nicely though, due to the need to clone components out of a standard storage.

#1515 would provide an alternate path to some of the use cases.

Some very limited workarounds may exist using commands (and entity commands) in certain use cases.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.