Decouple serialization and reflection #3664
Labels
A-Reflection
Runtime information about types
A-Scenes
Serialized ECS data stored on the disk
C-Code-Quality
A section of code that is hard to understand or change
C-Usability
A targeted quality-of-life change that makes Bevy easier to use
S-Needs-Design
This 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,
serde
serialization) are tightly coupled right now.For example,
Option<T>
'sReflect
implementation has aSerialize
trait 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_reflect
without usingserde
(either without any serialization or with an alternate backend) effectively impossible.What solution would you like?
serialize
feature flag.serde
should only be a dependency with theserde
flag enabled.impl_reflect_value
macro to account for whether or not this feature flag is enabled.Option
andHashSet
. We should ensure that these types can still be serialized if and only if the underlying values are serializable.serialize
method onReflect
. Instead, create a secondReflectSerialization
trait 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
serialize
as 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
serde
due to excessive compilation times.The text was updated successfully, but these errors were encountered: