bevy
bevy copied to clipboard
Scene fails to serialize
Bevy version
0.9.0 main 688f13c
What you did
I attempted to serialize a scene using the following code:
fn save_scene(world: &mut World) {
for entity in world
.query_filtered::<Entity, With<Camera>>()
.iter(world)
.collect::<HashSet<_>>()
{
world.despawn(entity);
}
let type_registry = world.resource::<AppTypeRegistry>();
let scene = DynamicScene::from_world(world, type_registry);
let serialized = scene
.serialize_ron(type_registry)
.expect("Failed to serialize the world");
#[cfg(not(target_arch = "wasm32"))]
IoTaskPool::get()
.spawn(async move {
fs::write("assets/scenes/test.scn.ron", serialized.as_bytes())
.expect("Failed to write to file");
})
.detach();
}
What went wrong
App panics and scene is not saved
Additional information
Logs
Failed to serialize the world: Message("no registration found for dynamic type with name bevy_render::view::visibility::ComputedVisibilityFlags")
I think it might be a result of #6305 but I am not certain.
Hmm. That feels like the sort of data that shouldn't be serialized.
Hmm. That feels like the sort of data that shouldn't be serialized.
I agree. I don't think it's anything I did as it saved flawlessly before updating and I haven't changed anything since. I'm guessing it worked before because ComputedVisibility held a u8 instead of ComputedVisibilityFlags so it didn't ask any questions but I don't know too much about how Bevy serializes data so I'm probably wrong.
i think (but am not sure that) this is because in #6305 the new ComputedVisibiltyFlags is never registered to the type registry.
however i do agree with alice that this shouldn't ever need to be serialized.
A short term fix would be to register the type.
A long term fix would likely to exclude computed types like GlobalTransform and ComputedVisibilty from scenes and just initialize their defaults on spawning a scene.
Note that, as a workaround, you can manually register that type for now.
This could have been fixed by #6725, please check if it resolves your use case. However, it might still not be able to serialize to ron due to the GlobalTransform bug (but can be into binary formats). There is an active PR to fix it #6580
#6725 and #6580 have been merged. Tentatively closing this. If there are still issues serializing specifically because of ComputedVisibility, please reopen this issue. Otherwise file a separate one.