-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Decouple serialization and reflection #3664
Copy link
Copy link
Closed
Labels
A-ReflectionRuntime information about typesRuntime information about typesA-ScenesComposing and serializing ECS objectsComposing and serializing ECS objectsC-Code-QualityA section of code that is hard to understand or changeA section of code that is hard to understand or changeC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplished
Metadata
Metadata
Assignees
Labels
A-ReflectionRuntime information about typesRuntime information about typesA-ScenesComposing and serializing ECS objectsComposing and serializing ECS objectsC-Code-QualityA section of code that is hard to understand or changeA section of code that is hard to understand or changeC-UsabilityA targeted quality-of-life change that makes Bevy easier to useA targeted quality-of-life change that makes Bevy easier to useS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplished
What problem does this solve or what need does it fill?
Reflection and serialization (specifically,
serdeserialization) are tightly coupled right now.For example,
Option<T>'sReflectimplementation has aSerializetrait bound.This can make it challenging to model types that should be reflected but not serialized (e.g. for fancy ECS tricks like trait queries or editor inspection, see #3580). Additionally, this makes relying on
bevy_reflectwithout usingserde(either without any serialization or with an alternate backend) effectively impossible.What solution would you like?
serializefeature flag.serdeshould only be a dependency with theserdeflag enabled.impl_reflect_valuemacro to account for whether or not this feature flag is enabled.OptionandHashSet. We should ensure that these types can still be serialized if and only if the underlying values are serializable.serializemethod onReflect. Instead, create a secondReflectSerializationtrait that handles this, and does not return an option. This method should return aBox<dyn Serializable>, allowing users to implement this trait with their own serialization backend.Alternatives considered
We could keep
serializeas a method onReflect. This is less useful, as being able to distinguish between serializable reflected objects and non-serializable ones at the type level is very relevant in end-user code. It also prevents us from hiding all of the serialization functionality behind a feature flag.Additional context
Issue created for @kabergstrom, who wants to avoid
serdedue to excessive compilation times.