-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use FromReflect
when extracting entities in dynamic scenes
#15174
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
This is actually something I originally wanted to add as part of the FromReflect
ergonomics RFC/implementation (for the reflection deserializer, not necessarily the one for bevy_scene
), so hopefully we can solve this problem at the root as well. I'm also hoping #13432 can help here eventually too.
Co-authored-by: Gino Valente <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you provide an example before and after scene for the migration guide? We don't have great tools here yet, but we should be able to do better.
FYI, |
Updated. Interesting that |
I believe so yes. |
Without a rigorous way to check every type, I just did a text scan and found only the glam types were missing. The bug is not as bad as I thought because, as far as I can tell, only the glam types have a differing serialization format (they serialize as sequences not maps). If the format is the same for reflect/native serialization the bug should not occur. I updated the migration guide which includes |
Great, thank you! |
…evyengine#15174)" This reverts commit 2ea51fc.
# Objective Fixes #15726 The extraction logic for components makes use of `FromReflect` to try and ensure we have a concrete type for serialization. However, we did not do the same for resources. The reason we're seeing this for the glam types is that #15174 also made a change to rely on the glam type's `Serialize` and `Deserialize` impls, which I don't think should have been merged (I'll put up a PR addressing this specifically soon). ## Solution Use `FromReflect` on extracted resources. ## Testing You can test locally by running: ``` cargo test --package bevy_scene ```
Objective
Fix #10284.
Solution
When
DynamicSceneBuilder
extracts entities, they are cloned viaPartialReflect::clone_value
, making them into dynamic versions of the original components. This loses any customReflectSerialize
type data. Dynamic scenes are deserialized with the original types, not the dynamic versions, and so any component with a custom serialize may fail. In this caseRect
andVec2
. The dynamic version includes the field names 'x' and 'y' but theSerialize
impl doesn't, hence the "expect float" error.The solution here: Instead of using
clone_value
to clone the components,FromReflect
clones and retains the original information needed to serialize with any customSerialize
impls. I think using something likereflect_clone
from (#13432) might make this more efficient.I also did the same when deserializing dynamic scenes to appease some of the round-trip tests which use
ReflectPartialEq
, which requires the types be the same and not a unique/proxy pair. I'm not sure it's otherwise necessary. Maybe this would also be more efficient when spawning dynamic scenes withreflect_clone
instead ofFromReflect
again?An alternative solution would be to fall back to the dynamic version when deserializing
DynamicScene
s if the custom version fails. I think that's possible. Or maybe simply always deserializing via the dynamic route for dynamic scenes?Testing
This example is similar to the original test case in #10284:
Migration Guide
The
DynamicScene
format is changed to use custom serialize impls so old scene files will need updating:Old:
New: