Skip to content

Conversation

janis-bhm
Copy link
Contributor

@janis-bhm janis-bhm commented Oct 3, 2025

Objective

Fixes #21293
Fixes #17314 to ensure that this is tested correctly.

Solution

when despawning an entity, previously the swapped in (archetype) or moved in entity (table) (which both require extra bookkeeping to update archetype or table rows) were marked as spawned_or_despawned by the location and tick that the to-be-removed entity was meant to be marked, while the to-be-removed entity wasn't marked.
As pointed out by @akimakinai in #19047, I've re-added the correct mark_spawn_despawn call to despawn_with_caller.

Testing

I've added a test spawned_after_swap_remove that ensures that despawning an entity by swapping doesn't effect other entities spawned_or_despawned location, and that it does effect the despawned entity's index's spawned_or_despawned location.

Co-Authored By: waterwhisperer24@qq.com

@alice-i-cecile alice-i-cecile added this to the 0.17.2 milestone Oct 3, 2025
@janis-bhm janis-bhm 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 labels Oct 3, 2025
@janis-bhm
Copy link
Contributor Author

The test only does anything when track_location is on, which doesn't appear to be the case for the tests in the CI? a bit unfortunate.

@alice-i-cecile
Copy link
Member

@janis-bhm can you incorporate the changes from #21359 into this PR please so we can merge it with passing tests?

@james7132 james7132 removed the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Oct 4, 2025
@james7132 james7132 enabled auto-merge October 4, 2025 00:02
@alice-i-cecile alice-i-cecile added the S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it label Oct 4, 2025
@james7132 james7132 added this pull request to the merge queue Oct 4, 2025
Merged via the queue into bevyengine:main with commit 20f6262 Oct 4, 2025
38 checks passed
mockersf pushed a commit that referenced this pull request Oct 4, 2025
# Objective

Fixes #21293
Fixes #17314 to ensure that this is tested correctly.

## Solution
when despawning an entity, previously the swapped in (archetype) or
moved in entity (table) (which both require extra bookkeeping to update
archetype or table rows) were marked as `spawned_or_despawned` by the
location and tick that the to-be-removed entity was meant to be marked,
while the to-be-removed entity wasn't marked.
As pointed out by @akimakinai in
[#19047](#19047), I've re-added
the correct `mark_spawn_despawn` call to `despawn_with_caller`.

## Testing

I've added a test `spawned_after_swap_remove` that ensures that
despawning an entity by swapping doesn't effect other entities
`spawned_or_despawned` location, and that it does effect the despawned
entity's index's `spawned_or_despawned` location.

Co-Authored By: waterwhisperer24@qq.com

---------

Co-authored-by: WaterWhisperer <waterwhisperer24@qq.com>
world.flush();

// SAFETY: `self.entity` is a valid entity index
unsafe {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little late here, but don't we still need to call mark_spawn_despawn() before flush() so that the value is updated before we run commands queued by any hooks?

...

Yeah, I just tested it, and it's possible to observe a stale value in a command, or to spawn a new entity that re-uses the index and have its spawed_by overwritten. It's very much an edge case, but let me go make a quick PR to change that ... #21397.

beicause pushed a commit to beicause/bevy that referenced this pull request Oct 6, 2025
…1364)

# Objective

Fixes bevyengine#21293
Fixes bevyengine#17314 to ensure that this is tested correctly.

## Solution
when despawning an entity, previously the swapped in (archetype) or
moved in entity (table) (which both require extra bookkeeping to update
archetype or table rows) were marked as `spawned_or_despawned` by the
location and tick that the to-be-removed entity was meant to be marked,
while the to-be-removed entity wasn't marked.
As pointed out by @akimakinai in
[bevyengine#19047](bevyengine#19047), I've re-added
the correct `mark_spawn_despawn` call to `despawn_with_caller`.

## Testing

I've added a test `spawned_after_swap_remove` that ensures that
despawning an entity by swapping doesn't effect other entities
`spawned_or_despawned` location, and that it does effect the despawned
entity's index's `spawned_or_despawned` location.

Co-Authored By: waterwhisperer24@qq.com

---------

Co-authored-by: WaterWhisperer <waterwhisperer24@qq.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 S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it

Projects

None yet

Development

Successfully merging this pull request may close these issues.

track_location shows spawn location as despawn location Enable track_location tests

5 participants