-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Allow registering components/resources from ReflectComponent/Resource #15453
Copy link
Copy link
Closed
Labels
A-ReflectionRuntime information about typesRuntime information about typesC-FeatureA new feature, making something new possibleA new feature, making something new possibleD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!
Description
What problem does this solve or what need does it fill?
I would like to be able to get or create a ComponentId with just TypeId (and TypeRegistry) assuming a given type reflects the required trait. This currently can only be done if a given component/resource has already been initialized (with Components::get_id and Components::get_resource_id).
A specific example: a scripting language that wants to check for existance of a resource/component (on an entity) where the resource resource/component is defined in rust.
What solution would you like?
For ReflectComponent:
- add a new function that takes
&mut Worldand callsworld.init_component::<T>()
For ReflectResource:
- would require adding a new method to
Worldthat initializes a resource without inserting- NOTE: based on current naming convention this should be called
init_resourcewhich is already used. Renameinit_componentandinit_component_with_desciptor#15451 proposes a rename of this group of methods. This would mean the new method would be calledregister_resource<T> - NOTE: this is different than Add
init_resource_with_descriptor#15448 as this method should return the sameComponentIdfor the same type if called multiple times
- NOTE: based on current naming convention this should be called
- add a new function that takes
&mut Worldand calls this new function
What alternative(s) have you considered?
- Require users to manually register all resources/components they are planning to use first (this is what I'm currently doing)
- Somehow initialize all registered types that
#[reflect(Component, Resource)]automatically when registering a type inside of the type registry.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-ReflectionRuntime information about typesRuntime information about typesC-FeatureA new feature, making something new possibleA new feature, making something new possibleD-StraightforwardSimple bug fixes and API improvements, docs, test and examplesSimple bug fixes and API improvements, docs, test and examplesS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!This issue is ready for an implementation PR. Go for it!