Help with removing instances

I will explain in depth the reason for which I need to do this:

I have a game, which randomly generates a grid of blocks, using 1 actor. The actor makes a bunch of instances of itself for performance reasons.
My grid of blocks also includes places where blocks aren’t at, but could be if you wanted to place one down. Here’s a picture example:

As you can see, I have air/empty blocks, and dirt blocks. The empty blocks are included in the arrays because you can place blocks their, so arrays reserve a space for them.

Now here is where the problem comes in:

I have it so that you can destroy blocks by clicking on them. What I do is I do a line trace to the block, subtrace some HP, check to see if HP < 0, and remove the instance. To know which instance to remove, I drag the ‘hit item’ return node from break hit result to the remove instance. The problem is that I know which item I clicked on, but don’t know which index I need to subtract HP from, because air blocks are skipped, and aren’t counted as instances/‘items’. Here is another picture to help you visualize.

4e07fed3fdff3d26633c3417078c4114ca1372a8.jpeg

So as you can see, the index of the item is different than the index I would need in the HP array. What happens is that if I tried too damage block 3 for example, it would destroy it immediately(rather than 3 hits/clicks) because my empty blocks have 0 HP.

Can anyone help me? I need to find out a way to get the proper array index from the ‘hit item’

I was thinking that maybe there is a way to spawn some ‘blank instances’ inside the empty blocks, that way the item index would match up with the arrays indexes. Can I do this?

You just need to ensure that each of your arrays have 30 members whether they have an item in each index or not. You need to create a placeholder for your empty blocks so that something takes up that space.

One of the methods I used previously involved spawning invisible collision volumes at each tile location. I would trace to the tile, get its index in the array, which would correspond to the index of every other data array. In your case, you would trace, hit the volume, and it would tell you that the space is empty.

Well each on of my arrays already has all of the blocks ( filled and empty ), but I have no ‘item’ for the empty blocks. It is the engine created ‘items’ array that doesn’t have them. Are you suggesting that I do ‘add instance’ for the empty spots as well, but use an invisible mesh?

You could add an invisible instance, though I found it easier to deal with invisible actors myself.

Well, my blueprint is as simple


So I’ll try and use instances. But now I’ve got a problem… It looks like each instanced static mesh component has it’s own array of ‘items’, which mean I have to use the same instanced static mesh component for both air and filled blocks. But how do I control visibility/collision per instance? Or is there a way to combine the ‘item’ list from both components?

Oh and I must add: I’d use actors, but my game’s “grid” is rather large, ~1,000,000 blocks or so. So using actors is extremely resource heavy. Any suggestions or way I can use one component but multiple settings (visibility, collision (per instance) ) ?

Alright, I’ve got an idea, but is has a problem :(. Since I have my BlockLocations array, I could check the BreakHitResult->Location, and see which index in my BlockLocations array is closest to the hit location. The problem is that even though I spawn blocks at the 100 mark for coords ( 0x, 100x, 200x etc…) it is possible for me to get a hit location of like -2.61x even though my block is at 0x. Anyone know how to stop that from happening?