Relationships are spawned separate from their bundle in Bevy 0.17
- 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
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