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::write_to_world_with multiple times with previously existing entities leads to inconsistent relationships. #18418

Open
andriyDev opened this issue Mar 19, 2025 · 0 comments
Labels
A-ECS Entities, components, systems, and events A-Scenes Serialized ECS data stored on the disk C-Bug An unexpected or incorrect behavior S-Needs-Design This issue requires design work to think about how it would best be accomplished

Comments

@andriyDev
Copy link
Contributor

Bevy version

f353cc3

What you did

let mut app = App::empty();
app.init_resource::<AppTypeRegistry>();
app.register_type::<Children>();
app.register_type::<ChildOf>();

let mut scene = Scene {
    world: World::new(),
};
let a = scene.world.spawn_empty().id();
let b = scene.world.spawn(ChildOf { parent: a }).id();
let c = scene.world.spawn(ChildOf { parent: b }).id();

let type_registry = app.world().resource::<AppTypeRegistry>().clone();

let mut entity_map = Default::default();
scene
    .write_to_world_with(app.world_mut(), &mut entity_map, &type_registry)
    .unwrap();

let b = entity_map[&b];
let c = entity_map[&c];

let d = app.world_mut().spawn(ChildOf { parent: b }).id();

scene
    .write_to_world_with(app.world_mut(), &mut entity_map, &type_registry)
    .unwrap();

assert_eq!(app.world().entity(d).get::<ChildOf>().unwrap().parent, b);

assert_eq!(
    &app.world()
        .entity(b)
        .get::<Children>()
        .unwrap()
        .iter()
        .cloned()
        .collect::<Vec<Entity>>(),
    &[c, d]
);

What went wrong

The relationships are inconsistent! We have a ChildOf component on d, but the Children of b does not contain d!

Additional information

This is a result of #17858.

@andriyDev andriyDev added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled A-ECS Entities, components, systems, and events A-Scenes Serialized ECS data stored on the disk S-Needs-Design This issue requires design work to think about how it would best be accomplished and removed S-Needs-Triage This issue needs to be labelled labels Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events A-Scenes Serialized ECS data stored on the disk C-Bug An unexpected or incorrect behavior S-Needs-Design This issue requires design work to think about how it would best be accomplished
Projects
None yet
Development

No branches or pull requests

1 participant