Skip to content

insert_with_relationship_insert_hook_mode still runs the relationship on_replace implementation. #18357

@andriyDev

Description

@andriyDev

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsA-ScenesSerialized ECS data stored on the diskC-BugAn unexpected or incorrect behaviorS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions