bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Scene fails to serialize

Open ShinySapphic opened this issue 3 years ago • 5 comments

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.

ShinySapphic avatar Nov 15 '22 02:11 ShinySapphic

Hmm. That feels like the sort of data that shouldn't be serialized.

alice-i-cecile avatar Nov 15 '22 02:11 alice-i-cecile

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.

ShinySapphic avatar Nov 15 '22 02:11 ShinySapphic

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.

soqb avatar Nov 15 '22 07:11 soqb

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.

james7132 avatar Nov 15 '22 22:11 james7132

Note that, as a workaround, you can manually register that type for now.

alice-i-cecile avatar Nov 16 '22 03:11 alice-i-cecile

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

sQu1rr avatar Nov 25 '22 00:11 sQu1rr

#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.

james7132 avatar Nov 26 '22 00:11 james7132