Skip to content

Inconsistent behaviour when using SpawnRelated with Observers #22011

@Freyja-moth

Description

@Freyja-moth

Bevy version and features

Main: 71114e1

What you did

Spawning related entities using SpawnRelated is inconsistent with Insert/Add observers.

fn print_name(
    insert: On<Insert, ChildOf>,
    names: Query<&Name>,
) -> Result<(), BevyError> {
    let name = names.get(insert.entity)?;

    dbg!(name);
}

fn spawn_widgets(
    mut commands: Commands
) {

    commands.spawn((
        UiRoot,
        // This will panic
        children!(
            (Button, Name::new("Special Button")), 
        ),
        // This will not panic
        Children::spawn_one((Button, Name::new("Different Button"))),
        // And neither will this
        Children::spawn(SpawnRelated(|parent: &mut RelatedSpawner| {
            parent.spawn((Slider, Name::new("Interesting Slider"));
        })
    ));
}

What went wrong

When using children!() it will panic with The query does not match entity (...).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-ECSEntities, components, systems, and eventsC-BugAn unexpected or incorrect behaviorS-Needs-InvestigationThis issue requires detective work to figure out what's going wrong

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions