bevyengine / bevyengine/bevy

Reflection - Add a way to register or modify `RequiredComponents` for a component whose type you don't know

Open
#18,420 0 comments 0 reactions 0 assignees View on GitHub
A-ECS A-Reflection C-Feature D-Straightforward S-Ready-For-Implementation X-Uncontroversial
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 you can:
- register a dynamic component with `World::register_component_with_descriptor`
- register required components for a component whose type you know at compile time via: `World::register_required_components()`
- retrieve a `&RequiredComponents` for any component
- Create a new component implementing type which initializes its `RequiredComponents` BUT PURELY with compile time information i.e. no `&self`

But there is no way to either (as far I can see):
- initialize your dynamic component with a specific `RequiredComponents`
- retrieve a `&mut` for the components `RequiredComponents` after the fact

## What solution would you like?

- Add ability to get to `&mut RequiredComponents` for any component
- Add `&self` to `Component::register_required_components`
- Add `RequiredComponents` argument to `register_component_with_descriptor` or an alternative function with that argument

## What alternative(s) have you considered?

- Perhaps there is a horribly cursed way to do this if you pass the required components via World through a resource or something, but even that seems difficult as there's no way to call `register_required_components` yourself.
- An ability to create a component with a custom `ComponentInfo` yourself

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.