Hi,
The instances are kept by the ISMC in a flat array. This means that as you remove instances, the instances indices change.
If you start with 5 instances for example: 0 1 2 3 4
If you remove instance 3, you end up with: 0 1 2 3
You do not end up with: 0 1 2 4
Instance 4 moved back to 3 as 3 was removed.
So you can’t really ‘bake’ the current list of indices in IntArray and expect these to be valid after you remove the first one.
The easiest solution is to not use IntArray and simply pick a random index between 0 (assuming you have at least 1 instance) and the max instance index (with is equal to instance count - 1).
As a side note, you can use the Is Valid Instance function to make sure your index is valid.
If you have a very specific list of indices you want to be potentially removed, while keeping other instances untouched (which is what I assume you are trying to achieve with your IntArray), then you will have to adjust the values of IntArray any time an instance is removed, which can be costly depending on the amount of instances you have.
Let’s say these are the current instances: 0 1 2 3 4 5 6 7 8 9
And this is your IntArray (the indices that are allowed to be removed): 1 2 3 7 8 9
If you remove instance 7: 0 1 2 3 4 5 6 [7] 8 9
Your new ISMC is: 0 1 2 3 4 5 6 7 8 where 7 and 8 were previously 8 and 9.
You first need to remove 7 from your IntArray: 1 2 3 8 9
Then you need to decrement (-1) all indices > 7 in IntArray: 1 2 3 [8 9]
Final result: 1 2 3 7 8
Also, in your screenshot, you are using Remove Index but you are providing the value of the IntArray. If you are using the value of IntArray at index 0, you should be removing index 0.
Alternatively, you could skip maintaining IntArray and, if applicable in your game, use functions from the ISMC like Get Instances Overlapping Sphere or Get Instances Overlapping Box to select the ‘removable’ instances in a defined area.