Failing to remove instances from instanced static mesh

I’m making a room generator which creates walls as parts of instanced static mesh. When the room is finished, it should remove a random item from each wall. I failed to implement that, and for debugging I tried to just remove specific items from the mesh, but it still doesn’t work.


Hi Krosenut,

What happens if you pass in either the Wall1 or Wall2 array to the RemoveInstances? Is it possible you have multiple instances in the same locations?

Yes, I found out that I was adding a row of walls every iteration of the loop in the same place. I fixed it, and now what’s left is to remove a part of wall on each side. But despite what I’m doing, the removal happens totally randomly, as if I’m removing random instances from the whole mesh array instead of separate wall arrays.


It almost looks like you’re adding the instance indexes for the 4th wall to the 3rd walls array (may not be 3rd and 4th , may be 2nd and 3rd etc). You could try adding a “PrintString” after each RemoveInstance to display the indexes, or move it to another function such as BeginPlay and set a breakpoint, then you could examine the arrays by hovering over them…

You cannot remove them one by one, not like this. Every time you try, the instance order and their indexed change - that’s the nature of (H)ISMs. Here’s the perfect order ruined by removing random instances:

Add the instances you wish to remove to an array instead and then:

image

Get rid of them all in one go. This will, of course, render your other arrays useless because they still store stale / invalid data.


One way to work with ISMs is to not remove instances at all. Move them where you cannot see them. Under the carpet you go.

2 Likes

Good spotting by @Everynone. You could also make your random holes before creating the instances and not add them there…

1 Like