Skip to content

Relationships are spawned separate from their bundle in Bevy 0.17 #21428

@cart

Description

@cart

Bevy version and features

Bevy 0.17.2

What you did

commands.spawn(Player, related!(Equipment[items::fire_staff(&sprites, &sprite_layouts)]));
...
pub fn on_item_equipped(
    trigger: On<Add, EquipmentOf>,
    mut commands: Commands,
    mut item_query: Query<(
        Option<&Equippable>,
        Option<&EquipmentOf>,
        Option<&mut Visibility>,
    )>,
) {
    let equipped_entity = trigger.event().entity;

    info!("{:?}", item_query.get_mut(equipped_entity));
    // prints None, Some, None
}

What went wrong

In Bevy 0.17, relationships using the related! spawn API are inserted first (separately from the rest of the bundle). This prevents developers from using lifecycle events on the relationship that access the contents of the bundle. This is a major functionality loss from Bevy 0.16, where this worked.

I believe this was introduced in #20772, which split this out in the interest of solving a stack overflow issue. This particular behavior was not really the cause of the stack overflow / I believe we can restore it in the context of the new system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorD-ComplexQuite challenging from either a design or technical perspective. Ask for help!D-UnsafeTouches with unsafe code in some wayS-Ready-For-ImplementationThis issue is ready for an implementation PR. Go for it!X-BlessedHas a large architectural impact or tradeoffs, but the design has been endorsed by decision makers

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions