-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
What problem does this solve or what need does it fill?
bevy_reflect uses TypeRegistry to keep track of metadata used to dynamic interact with Reflect types. This is also used by ser/de operations, like bevy_scene and any networking.
Users should keep a reference to a single TypeRegistry that contains all types registered and pass it around to Scenes, ReflectSerializer, *ReflectDeserializer and any type which needs to deal with its metadata, which is very verbose to carry around.
Also this make it hard to have custom ReflectSerialize and ReflectDeserialize implementations, since there is no TypeRegistry available, where in this case, users should make the TypeRegistry global available themselves.
Usually the TypeRegistry is written once, at the App startup, either by plugins or by any custom logic, and then read by any bevy_reflect operations which needs to know it's metadata.
What solution would you like?
Add a default global available TypeRegistry, to be used when a single TypeRegistry is required (which should cover most use cases), but keep TypeRegistry to be instantiated and be used individually when required (something like ReflectSerializer::with_registry).
- Make
TypeRegistryglobal available; - Change
ReflectSerializer/*ReflectDeserializer; to use globalTypeRegistryby default; - Add an option to use a custom
TypeRegistryon:ReflectSerializer;*ReflectDeserializer;
What alternative(s) have you considered?
Let users create a global available TypeRegistry, to be built after app startup and use it. This will solve the problem of accessing TypeRegistry inside a custom ReflectSerialize/ReflectDeserialize but keeping the verbosity of carrying around the TypeRegistry.
Additional context
I'll do some researches on this subject, but there are some questions which needs to be solved, mostly to know how far should we go with this enhancement:
- 1. Should we change
DynamicSceneto also use globalTypeRegistryby default? - 2. Should we remove the
App::register_typein favor of a staticTypeRegistry::register_type? - 3. Should we remove the resource
TypeRegistryfromApp?
Also, another questions to be answered:
- 1. There are some use cases where multiple
TypeRegistryshould be kept around? - 2. There are some use cases where new types will be registered, after the app startup stage?
Metadata
Metadata
Assignees
Labels
Type
Projects
Status