-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Automatically register types for Reflect #3936
Copy link
Copy link
Closed
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsA-ReflectionRuntime information about typesRuntime information about typesA-ScenesComposing and serializing ECS objectsComposing and serializing ECS objectsC-FeatureA new feature, making something new possibleA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesA "normal" level of difficulty; suitable for simple features or challenging fixesS-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-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsA-ReflectionRuntime information about typesRuntime information about typesA-ScenesComposing and serializing ECS objectsComposing and serializing ECS objectsC-FeatureA new feature, making something new possibleA new feature, making something new possibleC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useD-ModestA "normal" level of difficulty; suitable for simple features or challenging fixesA "normal" level of difficulty; suitable for simple features or challenging fixesS-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?
As seen in the examples, each type that we wish to reflect must be manually registered.
This is a serious frustration when using type reflection, and severely limits the ability to implement richer features using it (like trait queries), as we have no guarantee that resources / components are reflectable.
What solution would you like?
Reflecttrait to fully support all reasonable data types. Add reflection for enum types #1347 is particularly critical.Resourceopt-in, using a derive macro.Resource, and makeRes<T>: Resource + Send + Sync.Resourceand force users to use#[derive(Resource)].Reflect) all of the types used in it to theAppthat contains it. See the prior art on trait queries for an idea of how this might be done.Open questions
We may need to force an explicit
Eventtrait / derive that handles reflection as well in order to ensure thatRes<Events<T>>is reflectable.What alternative(s) have you considered?
Reducing this boilerplate is quite essential: currently, using scenes is very tedious due to this error-prone boilerplate.
However, there are several reasonable changes to consider:
Reflecta required subtrait ofComponentandResource. This does not play nice when external types are embedded in components and resources.Reflectin theComponent/Resourcederive. This is technically clearer, but introduces advanced concepts right away and adds to boilerplate.Additional context
This is an old idea, and certainly not entirely my own. It was previously discussed in #1843 / #2254 / bevyengine/rfcs#27.
This strategy is also useful for including other information in the appropriate traits, such as the size of assets / components / resources (seen in https://github.com/BGR360/bevy_datasize).
The same technology used above for trait registration would be very useful for #1515.