GetInstancesOverlappingSphere reports instances that have been removed

Have you seen this bug here? I wonder if it could be related, though it pertains to instances not rendering even though they are still in existence: Unreal Engine Issues and Bug Tracker (UE-53053)

The reason I wonder if its related, is that in that bug instances fail to render but their collision are still present. That however does not explain why GetInstanceCount() would be passing your check.

Looking at your code, the second check could fail if any instances make their way into the sphere size in the second GetInstancesOverlappingSphere call. How large of a sphere are you using, and are there many instances moving around at very high speed near the call? Note that if you aren’t moving instances around in world space, then this could not possibly be the issue.

Instead of the second check you are running, try logging the index values in removalIndexs2, and then also log the int32 returned by a call to GetInstanceCount(). This will indicate to you how many instances exist, and which ones are in the second collision sweep result. This could give you clues about which instances are either not being removed, or which are somehow finding their way into the sphere trace.

Another test you could do, is to perform your own sphere trace (calling it from GetWorld()) right before or after the second GetInstancesOverlappingSphere call, and examine the ‘Item’ member of the return FHitResult (Item is the index of the instance on the HISMC it hits, if any). Curious to see if it also detects an instance that shouldn’t be there.

Could could also try using sphere traces from GetWorld() (use a multi trace to get an array of FHitResult) instead of the sphere trace built into the HISMC, and collect the ‘Item’ numbers of the hits, and do a RemoveInstances using that array of indices instead. Perhaps the bug is in the HISMC sphere trace function.