-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Scene::write_to_world_with multiple times with previously existing entities leads to inconsistent relationships. #18418
Copy link
Copy link
Open
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsA-ScenesComposing and serializing ECS objectsComposing and serializing ECS objectsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplished
Description
Bevy version
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsA-ScenesComposing and serializing ECS objectsComposing and serializing ECS objectsC-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplishedThis issue requires design work to think about how it would best be accomplished