fix(physics): clear cached collisions when a collision component is removed#8898
Merged
Merged
Conversation
…emoved The rigid-body `collisions` map is keyed by entity GUID and was never cleared on entity destroy. Reloading the same scene recreates entities with identical GUIDs in a single task, so the stale entry (still referencing the destroyed entity) was reused, and triggerleave/collisionend stopped firing because `_cleanOldCollisions` inspects the cached, now-destroyed entity. Clear the entity's entry on collision `beforeremove`; every physics body entity has a collision component, so one hook covers triggers and rigid bodies. Fixes #5797 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Credit to @defektu, who diagnosed the root cause in the issue thread — that reloading the same scene recreates entities with the same GUIDs and leaves stale entries in the rigid-body collision tracking ("a flaw with collision objects' others list… not propagating"). This PR fixes that at the source (clearing the cached collision on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The rigid-body
collisionsmap is keyed by entity GUID and was never cleared when an entity is destroyed. Reloading the same scene recreates entities with identical GUIDs (fromresource_id) within a single task — no physics step runs in between — so the stale entry, still referencing the destroyed entity, was reused by the new same-GUID entity.From then on
triggerleave/collisionendnever fired, because_cleanOldCollisionsdecides which leave event to fire by inspecting the cached (now destroyed) entity, whosetrigger/bodyhad already been deleted on destroy.This clears the entity's cached collision on collision
beforeremove. Every physics body entity has a collision component, so this single hook covers both triggers and rigid bodies. Added a regression test.Fixes #5797
Checklist