bevyengine / bevyengine/bevy

Inconsistent behaviour when using SpawnRelated with Observers

Open
#22,011 0 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Bug S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
4d 8m
Merged PRs (30d)
147

Description

## Bevy version and features

Main: `71114e1`

## What you did

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

```rust
fn print_name(
insert: On,
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 (...)`.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.