-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Fix: deserialize DynamicEnum
using index
#12464
Fix: deserialize DynamicEnum
using index
#12464
Conversation
I think I found the fix if you want to incorporate it in this PR: The problem is here: bevy/crates/bevy_reflect/src/serde/de.rs Line 757 in 0e6a171
We need to change it to: let variant_name = variant_info.name();
let variant_index = self
.enum_info
.index_of(variant_name)
.expect("variant should exist");
dynamic_enum.set_variant_with_index(variant_index, variant_name, value); |
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.
Great start! Can you add a matching test in bevy_reflect to check the serialization there? Presumably that's where the actual bug is: the scene machinery is likely redundant.
DynamicScene
reserializationDynamicEnum
using index
Awesome I added the |
Yeah I think you can remove it. It would be nice to have a re-serialization test but I think the reflection test sorta makes it redundant. Maybe if there's certain behavior we want to verify re-serializes correctly, we add the test then. But yeah as for now, I don't think it's super necessary. |
In favor of `bevy_reflect::should_reserialize`
Okay, refactored
Did we catch another bug? commenting out btw i also deduplicated the three identical |
No I think this is expected behavior. We're serializing the Rust name but saying we expect the custom name (for a user the fix would be to register Maybe let's try changing |
Great yep using |
Great stuff: thanks for the contribution! |
# Objective - Addresses #12462 - When we serialize an enum, deserialize it, then reserialize it, the correct variant should be selected. ## Solution - Change `dynamic_enum.set_variant` to `dynamic_enum.set_variant_with_index` in `EnumVisitor`
Objective
DynamicScene
- Malformed enum when reserializing #12462Solution
dynamic_enum.set_variant
todynamic_enum.set_variant_with_index
inEnumVisitor