Closed
Description
openedon Oct 8, 2024
Bevy version
0.15.0-dev - rev 0c959f77007c29eead7f902bddd3342a1ecbca20
What you did
Attempted to serialize and then deserialize a resource with a Vec3
What went wrong
A Vec3 is serialized as a 'list' in components but a 'map' in resources. Issue is constistent in both ron
and serde_json
(
resources: {
"test::MyType": ((
x: 1.0,
y: 2.0,
z: 3.0,
)),
},
entities: {
4294967296: (
components: {
"test::MyType": ((1.0, 2.0, 3.0)),
},
),
},
)
Full Reproducable
#[cfg(test)]
mod test {
use anyhow::Result;
use bevy::prelude::*;
use bevy::reflect::erased_serde::__private::serde::de::DeserializeSeed;
use bevy::scene::ron;
use bevy::scene::serde::SceneDeserializer;
use bevy::scene::serde::SceneSerializer;
#[derive(Resource, Component, Reflect)]
#[reflect(Resource, Component)]
struct MyType(pub Vec3);
#[test]
fn works() -> Result<()> {
let mut app = App::new();
app.register_type::<MyType>();
app.insert_resource(MyType(Vec3::new(1., 2., 3.)));
let entity = app.world_mut().spawn(MyType(Vec3::new(1., 2., 3.))).id();
let world = app.world();
let scene = DynamicSceneBuilder::from_world(world)
.extract_resources()
.extract_entities(vec![entity].into_iter())
.build();
let registry = app.world().resource::<AppTypeRegistry>().read();
let serializer = SceneSerializer::new(&scene, ®istry);
let str = ron::ser::to_string_pretty(&serializer, Default::default())?;
let mut deserializer = ron::de::Deserializer::from_str(&str)?;
println!("{}", str);
SceneDeserializer {
type_registry: ®istry,
}
.deserialize(&mut deserializer)?;
Ok(())
}
}
Additional information
Possibly related to #15174, some discussion in discord here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Metadata
Assignees
Labels
Fundamental domain-agnostic mathematical operationsFundamental domain-agnostic mathematical operationsRuntime information about typesRuntime information about typesAn unexpected or incorrect behaviorAn unexpected or incorrect behavior