-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Bevy version
What you did
let app = App::new();
let world = app.world_mut();
let parent = world.spawn_empty().id();
let child = world
.spawn(ChildOf(parent))
.insert_with_relationship_insert_hook_mode(ChildOf(parent), RelationshipInsertHookMode::Skip);
assert!(world.entity(parent1).get::<Children>().is_some());
We made child a ChildOf parent, then we reinserted the ChildOf without its insert hooks. We'd expect the parent to still have the Children component from the initial hook.
What went wrong
The parent is missing the Children component since the on_replace hook ran!
#17858 made it so that relationship hooks do not run when spawning scenes. However, it did not prevent on_replace hooks. This can result in a relationship being removed, but the corresponding relationship not being inserted back.
This only applies when the entity already has the component being inserted. In many cases this is not a problem - for entity cloning, the entity doesn't have any relationships, so nothing breaks. For spawning scenes from scratch, it is also not a problem. However for scene hot-reloading, this is a problem.