InstancedStaticMesh Overlapping Sphere 'misses' instances

Hey,

I’ve set up a 2D array of InstancedStaticMesh instances, and I’m using the GetInstancesOverlappingSphere function to try to remove any that show up within a certain radius of a given point - the goal is to create an “explosion” and have the pieces there removed and replaced. The blueprint is simple, as seen below:

However, not all pieces within the radius, when called are removed, see [here][2]. I’m calling explosions in the same locations, but not all pieces are recognized. Any ideas whats happening?

I’d encourage you to move this to Bug Reports (you can do this via ‘Move to Space’ option) and provide some reproduction steps. Or maybe you’ve already solved it? I have a similar problem, Get Instances Overlapping Sphere doesn’t get all the instances, even if they’re totally inside the sphere. I’m on 4.12.

The “get instances overlapping sphere” may or may not work, but in your picture, the main problem is that you are, just like I did, removing instances directly from an array which you then continue to work on. What I mean is, as you remove one item, it resizes so now the next item may actually be the wrong item.

  • Make an int array and save the “get instances overlapping sphere” result.
  • Use the Max Of Int Array node on the int array; we need to work from the highest instance index to lowest so that we do not remove the wrong item.
  • After the Loop Body pin you need 2 new int variables, one that holds the index of max value and one for the max value. This works without saving them in variables but now we don’t have to run the Max Of Int Array function over and over.
  • Now’s the time to save the transform if you need to. The Instance Index input should be connected to the Max Value.
  • We can now remove the instance, instance index should once again be the max value int.
  • Now this is important: if we do nothing, the “Max Of Int Array” is going return the same value we just used, meaning we could possible remove a wrong item over and over. But if we remove it, once again since we are working with an array so we can’t just remove it. That would resize it and not all the items would be processed. We use the Set Node Elem for our int array, its index should be the “index of max value” and we set it to -1 to ensure it will not be caught as a new candidate for “max of int array”.
  • The Loop body is now done as far as removal of the correct item goes. But maybe you still want to do other things like “add instance”.
  • However, the last thing we should do is after the completed pin of the for loop, clear the int array.

I have now learned that if I need to remove more than one item from an array, think about it some.

That’s interesting @ste1nar

But there is also the RemoveInstances node, which will clear them all, just give the reference to the array result of the sphere overlap.

For example with a foreachloop, do anything per instance during the loop body - but not delete, as @ste1nar made clear … then, from the Complete pin, call RemoveInstances.

It seems the RemoveInstances node is only available for the hierachical instanced static mesh component