Skip to content

Observers and hooks doesn't pair well with mapped entities #14465

@Shatur

Description

@Shatur

Bevy version

v0.14.0

What you did

I have a component that stores an entity. The component implements and reflects MapEntities, so on scene deserialization it automatically maps entities inside it.

What went wrong

When I implement on_add hook or OnAdd observer for such component, it triggers before MapEntities which results in invalid entity access.
It happens because we insert components here:

reflect_component.copy(
&self.world,
world,
scene_entity.id(),
*entity,
&type_registry,
);

But entities mapped later:
for registration in type_registry.iter() {
if let Some(map_entities_reflect) = registration.data::<ReflectMapEntities>() {
map_entities_reflect.map_all_entities(world, entity_map);
}

I think we should map entities before the insertion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsA-NetworkingSending data between clients, servers and machinesA-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

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions