bevyengine / bevyengine/bevy

Required components cannot be registered just with ComponentIds

Open
#17,910 1 comment 1 reaction 0 assignees View on GitHub
A-ECS 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?

Registering required components is done through [try_register_required_components](https://docs.rs/bevy/latest/bevy/prelude/struct.World.html#method.try_register_required_components) (or equivalent functions in other types). This expects the components as static types in the generic parameters `T` and `R`. There's [get_required_components_by_id](https://docs.rs/bevy/latest/bevy/prelude/struct.World.html#method.get_required_components_by_id) that returns the list of required components as an immutable list.

However, I don't see a way to register required components just by passing component ids. This is necessary for runtime-defined components.

## What solution would you like?

Implement a function `try_register_required_components_by_id` that gets the base component and its required component by id. I don't know how to handle `try_register_required_components_with`, but there should also be a way to do that.

## What alternative(s) have you considered?

I've looked through the code. There's a `get_required_components_mut` in `Components`, but that one is `pub(crate)`. There's `register_required_components` that's also `pub(crate)`, but that one still needs some type `R` anyways.

So, I'm out of ideas how to get the current public API to do this.

## Additional context

All my research happened on the main branch of bevy (`82f6f704dad816e91a47cf72664db6289b179c26`).

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.