-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
A-ReflectionRuntime information about typesRuntime information about typesA-ScenesSerialized ECS data stored on the diskSerialized ECS data stored on the diskC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behavior
Description
Here is how I am currently serializing my game state:
pub fn save_state(world: &mut World) {
let type_registry = world.resource::<AppTypeRegistry>();
let scene = DynamicScene::from_world(world, type_registry);
let ser = SceneSerializer::new(&scene, type_registry);
let mut buf = Vec::new();
ser.serialize(&mut Serializer::new(&mut buf)).expect("Error serializing scene");
IoTaskPool::get()
.spawn(async move {
File::create(format!("save/gamestate.mp"))
.and_then(|mut file| file.write(buf.as_slice()))
.expect("Error writing scene to file");
})
.detach();
}It serializes to the messagepack format perfectly fine, but when I try to deserialize:
fn load_state(registry: &Res<AppTypeRegistry>) -> Result<DynamicScene, ()> {
let path = "save/gamestate.mp";
if !Path::new(path).exists() {
info!("Could not find path");
return Err(());
}
let file = File::open(path).expect("Could not open save file");
let mut reader = BufReader::new(file);
let de = SceneDeserializer {
type_registry: ®istry.read(),
};
de.deserialize(&mut Deserializer::new(&mut reader)).map_err(|_| ())
}It doesn't work, returning an Err at de.deserialize.
The error: Value Syntax("invalid type: string \"bevy_transform::components::transform::Transform\", expected a borrowed string")
Here are my imports:
use bevy::{
prelude::*,
scene::serde::{SceneSerializer, SceneDeserializer}, tasks::IoTaskPool,
};
use rmp_serde::{Serializer, Deserializer};
use serde::{Serialize, de::DeserializeSeed};
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_startup_system(setup_state);
}
fn setup_state(
registry: Res<AppTypeRegistry>,
) {
load_state(®istry);
}Version: 0.9.1
Platform: Linux x86-64
Metadata
Metadata
Assignees
Labels
A-ReflectionRuntime information about typesRuntime information about typesA-ScenesSerialized ECS data stored on the diskSerialized ECS data stored on the diskC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behavior
Type
Projects
Status
Done