Adding and removing HISM index by location in a TMap via Blueprint

Hey all!

I’m spawning HISM and storing their location in a TMap as follows:
Key: IntPoint (location) ← this make it easier to ‘find’ by IntPoint
Value: HISM index

When I remove a HISM by index, the map is useless because all the index are off.

Example:
Key - Value
0,0 = 0
0,1 = 1
0,2 = 2
0,3 = 3
0,4 = 4

If I remove HISM index 2, I assume 4 becomes 3 and 3 become 2, making anything after IntPoint index 2 incorrect (0,2 - 0,3 - 0,4). The only way I can think to fix this is to iterate through my TMap and shift 2-4 down in a For Loop. This doesn’t seem like the most efficient way to handle the situation, especially if I’m dealing with thousands of HISMs. Is there a better way to keep track of these?

I’m storing them via IntPoints so I don’t have to do a line trace. I just look up where the player is trying to interact and remove the HISM that’s there.

Any help would be greatly appreciated!

Thanks.

Hi whynotTheGreat,

You can use UHierarchicalInstancedStaticMeshComponent - when that one removes instances it swaps the last item in their array with the one being removed - you just have to do the same with your map.

The UHierarchicalInstancedStaticMeshComponent and UInstancedStaticMeshComponent do have an array of transforms as well - you could look at that too…

1 Like

Hey RecourseDesign,

Thanks for the quick reply! I’ll look into UHierarchicalInstancedStaticMeshComponent and UInstancedStaticMeshComponent. Sounds like they might do the trick if they store transforms.

1 Like

I should have specified, this is all via Blueprint. Not sure I have access to UHierarchicalInstancedStaticMeshComponent in there.

Sorry, without the U :slight_smile:
image