Skip to content

Fix observers' access to relationship data during despawn_related#20258

Merged
alice-i-cecile merged 2 commits intobevyengine:mainfrom
muddxyii:fix-despawn-related-observer-access
Jul 27, 2025
Merged

Fix observers' access to relationship data during despawn_related#20258
alice-i-cecile merged 2 commits intobevyengine:mainfrom
muddxyii:fix-despawn-related-observer-access

Conversation

@muddxyii
Copy link
Contributor

Objective

Solution

  • Changed despawn_related to use get() instead of take() to preserve relationship components during the despawn process
  • Collect entities into a vector before despawning to ensure the relationship data remains accessible to observers and hooks

Testing

  • Added test despawn_related_observers_can_access_relationship_data that reproduces the issue scenario

@alice-i-cecile alice-i-cecile added this to the 0.17 milestone Jul 23, 2025
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Jul 23, 2025
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left a suggestion for a clarifying comment, but this is fundamentally a good fix and I really appreciate the regression test.

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
@Trashtalk217 Trashtalk217 added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jul 24, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jul 27, 2025
Merged via the queue into bevyengine:main with commit ce57258 Jul 27, 2025
34 checks passed
@muddxyii muddxyii deleted the fix-despawn-related-observer-access branch July 27, 2025 17:38
mate-h pushed a commit to mate-h/bevy that referenced this pull request Jul 28, 2025
…evyengine#20258)

# Objective

- Fix issue where observers cannot access relationship data during
`despawn_related`
- Fixes bevyengine#20106

## Solution

- Changed `despawn_related` to use `get()` instead of `take()` to
preserve relationship components during the despawn process
- Collect entities into a vector before despawning to ensure the
relationship data remains accessible to observers and hooks

## Testing

- Added test `despawn_related_observers_can_access_relationship_data`
that reproduces the issue scenario

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
tychedelia pushed a commit to tychedelia/bevy that referenced this pull request Jul 31, 2025
…evyengine#20258)

# Objective

- Fix issue where observers cannot access relationship data during
`despawn_related`
- Fixes bevyengine#20106

## Solution

- Changed `despawn_related` to use `get()` instead of `take()` to
preserve relationship components during the despawn process
- Collect entities into a vector before despawning to ensure the
relationship data remains accessible to observers and hooks

## Testing

- Added test `despawn_related_observers_can_access_relationship_data`
that reproduces the issue scenario

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Uncontroversial This work is generally agreed upon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

despawn_related removes relationship before calling observers and hooks

3 participants

Comments