-
-
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!
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!
What problem does this solve or what need does it fill?
I would like to be able to get or create a
ComponentIdwith justTypeId(andTypeRegistry) assuming a given type reflects the required trait. This currently can only be done if a given component/resource has already been initialized (withComponents::get_idandComponents::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:&mut Worldand callsworld.init_component::<T>()For
ReflectResource:Worldthat initializes a resource without insertinginit_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>init_resource_with_descriptor#15448 as this method should return the sameComponentIdfor the same type if called multiple times&mut Worldand calls this new functionWhat alternative(s) have you considered?
#[reflect(Component, Resource)]automatically when registering a type inside of the type registry.