When I moved my project to 4.17 I realize that instance static mesh stopped working. It seems like invalid index is returned if one of the instances are removed. It only happens for specific instances.
To reproduce:
1.Create instances
2.Use on component begin overlap and try to destroy from SwapResult->HitItem;
3.Do it for few elements - Index become invalid and at some point instances are not removed anymore.
Workaround is to initialize all instances: Remove Instance, Remember all instances, Clear Instances, Add all instances.
In the video it’s not removing anything. It is returning 0 indexes. It is not removing elements anymore after switch from 4.16 to 4.17 but maybe it’s intended behavior.
That was a bug in 4.16/4.17 when removing ISM it was not giving you index of correct instance. It always should in my opinion, otherwise you would never know instance you are interacting with.
This is because each time you remove an item, the total array of those instances is re-sized. So if you have 50 blocks there and the first one is “0”, if you remove that “0” the next block in line will then become the new “0” and the total array will become 49 instead of 50. I am dealing with a bug caused from this same issue.
In my game, a player can mine ores. Lets say there are 5 iron ore nodes on my map. If a player mines an iron ore, my code properly removes that specific iron node from the game for 20 seconds. After 20 seconds, the iron ore respawns. If I wait for the ore to repsawn before I mine another ore, the whole process works fine, but if I mine an ore while waiting for another ore node to respawn, it will remove the wrong ore node or not remove one at all because the array has been changed from its original state.
I have no idea on what a workaround would look like, but that’s the problem.
Okay I see. Looking at my problem a little harder revealed that the indexing isn’t the problem for me. When my instanced static meshes are set to respawn, they use two stored variable values; instance index & instance transform. So my problem stems from, if i start mining a new node before the first one respawns, I am updating those two variables so I will try to respawn in the location that I am currently mining not its original location.