-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a simple method to get a ComponentId
for a given Component
type
#5060
Comments
This should be very easy, but that code is not exactly the most approachable, so no Good-First-Issue tag here. |
I'm not clear on how this or the I started implementing it by matching the parameters of Besides that, I feel like providing a |
Thanks for investigating @GarettCooper. I think your criticisms are very fair! After discussing this with @DJMcNab and @james7132, I think we should add two methods:
We should not add this as a method to As part of this PR, we should add basic docs to |
ComponentId
from a Component
ComponentId
for a given Component
type
# Objective - Simplify the process of obtaining a `ComponentId` instance corresponding to a `Component`. - Resolves bevyengine#5060. ## Solution - Add a `component_id::<T: Component>(&self)` function to both `World` and `Components` to retrieve the `ComponentId` associated with `T` from a immutable reference. --- ## Changelog - Added `World::component_id::<C>()` and `Components::component_id::<C>()` to retrieve a `Component`'s corresponding `ComponentId` if it exists.
# Objective - Simplify the process of obtaining a `ComponentId` instance corresponding to a `Component`. - Resolves bevyengine#5060. ## Solution - Add a `component_id::<T: Component>(&self)` function to both `World` and `Components` to retrieve the `ComponentId` associated with `T` from a immutable reference. --- ## Changelog - Added `World::component_id::<C>()` and `Components::component_id::<C>()` to retrieve a `Component`'s corresponding `ComponentId` if it exists.
# Objective - Simplify the process of obtaining a `ComponentId` instance corresponding to a `Component`. - Resolves bevyengine#5060. ## Solution - Add a `component_id::<T: Component>(&self)` function to both `World` and `Components` to retrieve the `ComponentId` associated with `T` from a immutable reference. --- ## Changelog - Added `World::component_id::<C>()` and `Components::component_id::<C>()` to retrieve a `Component`'s corresponding `ComponentId` if it exists.
What problem does this solve or what need does it fill?
Being able to extract the
ComponentId
for a given component of typeC
is surprisingly unintuitive.What solution would you like?
Create a public method on
Component
that mirrorsBundle::component_ids()
.EDIT: see below; this isn't the right API. These methods should live on
World
andComponents
instead.What alternative(s) have you considered?
world.init_component::<C>()
. This is unintuitive, but basically works.(C, )::component_ids(&mut components, &mut storages).iter().next().unwrap()
. Which is more than a little cursed.Additional context
Discovered while working on #1481 with @plof27.
The text was updated successfully, but these errors were encountered: