Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scene fails to serialize #6627

Closed
ShinySapphic opened this issue Nov 15, 2022 · 7 comments
Closed

Scene fails to serialize #6627

ShinySapphic opened this issue Nov 15, 2022 · 7 comments
Labels
A-Scenes Serialized ECS data stored on the disk C-Bug An unexpected or incorrect behavior
Milestone

Comments

@ShinySapphic
Copy link
Contributor

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 ShinySapphic added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Nov 15, 2022
@alice-i-cecile alice-i-cecile added A-Scenes Serialized ECS data stored on the disk and removed S-Needs-Triage This issue needs to be labelled labels Nov 15, 2022
@alice-i-cecile
Copy link
Member

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

@ShinySapphic
Copy link
Contributor Author

ShinySapphic commented Nov 15, 2022

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.

@soqb
Copy link
Contributor

soqb commented Nov 15, 2022

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.

@james7132
Copy link
Member

james7132 commented Nov 15, 2022

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.

@alice-i-cecile
Copy link
Member

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

@alice-i-cecile alice-i-cecile added this to the 0.9.1 milestone Nov 16, 2022
@sQu1rr
Copy link
Contributor

sQu1rr commented Nov 25, 2022

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

@james7132
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Scenes Serialized ECS data stored on the disk C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

5 participants