Zeenobit / moonshine_save

A save/load framework for Bevy game engine.
MIT License
81 stars 9 forks source link

Error loading bevy_core::name::Name component #11

Closed keis closed 5 months ago

keis commented 5 months ago

Trying to load a save file with name components results in the following error but only when the bevy serialize feature is enabled

ERROR moonshine_save::load: load failed: Ron(Message("Expected string"))

These modifications to the example should be enough to showcase the problem

diff --git a/Cargo.toml b/Cargo.toml
index c4c68b5..e122309 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -18,6 +18,7 @@ bevy_hierarchy = "0.13.*"
 bevy_reflect = "0.13.*"
 bevy_scene = "0.13.*"
 bevy_utils = "0.13.*"
+bevy_core = { version = "0.13.*", features = ["serialize"] }
 moonshine-util = { version = "0.2.0", path = "../util" }

 [dev-dependencies]
diff --git a/examples/army.rs b/examples/army.rs
index 908c701..0235824 100644
--- a/examples/army.rs
+++ b/examples/army.rs
@@ -300,7 +300,9 @@ fn add_melee_button_clicked(
     mut commands: Commands,
 ) {
     if let Ok(Interaction::Pressed) = query.get_single() {
-        let weapon = commands.spawn(WeaponBundle::new(Melee)).id();
+        let weapon = commands
+            .spawn((Name::new("Melee Weapon"), WeaponBundle::new(Melee)))
+            .id();
         commands.spawn(SoldierBundle::new(weapon));
     }
 }
Zeenobit commented 5 months ago

@keis Can you give me some more information about this feature? I'm not familiar with "serialize" and having trouble finding documentation. What's the expected behavior?

Or rather, why are using the "serialize" feature?

keis commented 5 months ago

I'm not really sure tbh, the feature gets enabled by another dependency, leafwing-input-manager, in my project.

keis commented 5 months ago

I can see that this feature does indeed changing the name component is some way https://github.com/bevyengine/bevy/blob/main/crates/bevy_core/src/name.rs#L25

Zeenobit commented 5 months ago

Yah I've been trying to figure it out from Bevy code, but it's very strange.

It seems like bevy_scene uses "serialize" by default, which guards the serialize_ron function used by Moonshine. Without it, Bevy cannot serialize as far as I can tell (I see no alternative serialization code path).

But this feature isn't enabled by default at the root crate. I'm not sure why it isn't, or what enabling it changes.

So I'm not sure what the intent behind the feature is, or what the alternative solution would be.

Zeenobit commented 5 months ago

Based on my investigation, this is a known issue: https://github.com/bevyengine/bevy/issues/12001

I'm gonna close this one, but feel free to open a new issue if it's still a problem after 0.13.1