You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the way transitionArchetypes works, transitioning from the same archetype to itself will always set the entityRecord.indexInArchetype to the number of elements in archetype.entities + 1, but it will also then put it back in the position it previously held. This leads to the indexInArchetype being 1 higher than the number of elements in archetype.entities every time. If additional entities are then added to it, multiple entities will have the same reference to the same element in the list. This makes it possible to remove an entity from archetype.entities that exists without removing the element that no longer exists.
The example above is a bit contrived, but I think the more common case would be if you had an entity that had no components and then you despawn it. Both executeDespawn and executeReplace have this issue because they start by transitioning to the rootArchetype before anything else.
I would expect to see this happen if, for example, the server is replicating entities to the client, and the client then removes all components from one such entity without despawning it, and eventually the server tells it to despawn the entity.
The text was updated successfully, but these errors were encountered:
As mentioned in the discord, I think the best solution is to include an if archetype == oldArchetype then return
Another possible solution would be to prevent this in executeDespawn / executeReplace since they always transition to rootArchetype even if it currently is the rootArchetype.
Description
With the way transitionArchetypes works, transitioning from the same archetype to itself will always set the entityRecord.indexInArchetype to the number of elements in archetype.entities + 1, but it will also then put it back in the position it previously held. This leads to the indexInArchetype being 1 higher than the number of elements in archetype.entities every time. If additional entities are then added to it, multiple entities will have the same reference to the same element in the list. This makes it possible to remove an entity from archetype.entities that exists without removing the element that no longer exists.
Steps to reproduce
^ Guaranteed to get the above error
Expected behavior
The example above is a bit contrived, but I think the more common case would be if you had an entity that had no components and then you despawn it. Both executeDespawn and executeReplace have this issue because they start by transitioning to the rootArchetype before anything else.
I would expect to see this happen if, for example, the server is replicating entities to the client, and the client then removes all components from one such entity without despawning it, and eventually the server tells it to despawn the entity.
The text was updated successfully, but these errors were encountered: