24-04-2024, 08:46 AM
(This post was last modified: 24-04-2024, 08:52 AM by josemendez.)
Hi Guillaume!
The reason why UpdateWorld iterates over cell spans instead of colliders is because we want to remove invalid colliders.
When a collider is invalidated for some reason (for instance, it has been destroyed), it is moved to the end of the collider list, using a typical swapback operation while keeping the capacity of the list intact.
So at any given time, all invalid colliders are past colliders.count but before cellSpans.count. It is fine to access past colliders.count, since a lists' backing array is always larger than its count. (capacity >= count)
If you look at the end of the IdentifyMovingColliders method, you'll see a comment explaining this:
I see no images attached to your email, and no stacktrace/description of the error you're getting, other than it happens in "IdentifyMovingColliders.Execute". Could you share more information?
kind regards,
The reason why UpdateWorld iterates over cell spans instead of colliders is because we want to remove invalid colliders.
When a collider is invalidated for some reason (for instance, it has been destroyed), it is moved to the end of the collider list, using a typical swapback operation while keeping the capacity of the list intact.
So at any given time, all invalid colliders are past colliders.count but before cellSpans.count. It is fine to access past colliders.count, since a lists' backing array is always larger than its count. (capacity >= count)
If you look at the end of the IdentifyMovingColliders method, you'll see a comment explaining this:
Quote:// if the collider is at the tail (removed), we will only remove it from its current cellspan.
// if the new cellspan and the current one are different, we must remove it from its current cellspan and add it to its new one.
if (i >= colliderCount || cellIndices[i] != newSpan)
{
// Add the collider to the list of moving colliders:
movingColliders.Enqueue(new MovingCollider()
{
oldSpan = cellIndices[i],
newSpan = newSpan,
entity = i
});
// Update previous coords:
cellIndices[i] = newSpan;
}
I see no images attached to your email, and no stacktrace/description of the error you're getting, other than it happens in "IdentifyMovingColliders.Execute". Could you share more information?
kind regards,