bevyengine / bevyengine/bevy

Relationships are spawned separate from their bundle in Bevy 0.17

Open
#21,428 0 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Bug D-Complex D-Unsafe S-Ready-For-Implementation X-Blessed
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 16h
Merged PRs (30d)
171

Description

## Bevy version and features

Bevy 0.17.2

## What you did

```rust
commands.spawn(Player, related!(Equipment[items::fire_staff(&sprites, &sprite_layouts)]));
...
pub fn on_item_equipped(
trigger: On,
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 https://github.com/bevyengine/bevy/pull/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.

Contributor guide

Open the contributing guide

Research direction

Start with the `related!` spawn API and inspect the changes from PR #20772, focusing on how relationship insertion is separated from the rest of the bundle. Reproduce the provided `EquipmentOf` lifecycle-event example and verify that the event can access the related entity's bundle contents without reintroducing the reported stack-overflow problem.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.