How to identify an 'Instanced Static Mesh'-instance by Index after 'Remove Instance'

Hi,

i am having a problem with removing specific instances of a grid of instanced static meshes by a given X-Y-grid-position, because they lose their indices after using the ‘Remove Instance’-Node in blueprints.

For the first remove this is fine, because all instances still have their original index, but by removing one, all other instances with a index higher than the one which has been removed seem to get their indexes decremented by 1 so that there are no empty index-numbers in the array.

So if i remove the instance with the index 0, the prior instance with index 1 gets index 0 and so on. This is a problem for me, because all instances have their fixed location in a X/Y-grid-system, but their indices aren’t a key to identify any of them after all their indices got shifted.

For Example this is a 3x3 grid of instances represented by their index:

2 5 8
1 4 7
0 3 6

if i remove the instances with index 0 (X:0, Y:0), 4 (X:1, Y:1) and 6 (X:2, Y:0) it looks like this:

1 3 5
0 x 4
x 2 x

small x indicates where an instance has been removed.

So if i now want to remove instance at X:1 Y:2, it’s very hard to reconstruct which index it has. I have to calculate how many instances have been removed before and after every instance to guess their new index.

Because indices are supposed to identify something it seems not logical to me, that the instances get their indices changed. Am i misunderstanding how the indices work and how to access them correctly or is there any workaround to find out which instance has which index after several of them have been removed?

I’m wondering this myself too. I currently have a grid of structs setup, with an index reference for the instance linked to Structs. The visual representation of this grid are a bunch of instances of 3 separate instanced static mesh components.

Lets say I change a tile from FLOOR to WALL
I than loop through my array of structs, whenever he sees a FLOOR, he checks if the index of that tile is higher than the the index of the tile I just changed. If so, it removes 1 from structs instance-Index to compensate for the array shifting.

This obviously is a horrible method. However, it was the only way I got it to work so far. Help greatly appreciated!

This is the same (horrible) method which i considered. But i am still hoping that the changing indices is a bug and it will change in some near future engine version. that part of my project is on hold since then so the blueprints get no unnecessary complex workarounds.

i am not sure if the issue should be reported as a bug or if it is working as intended for some reasons and i am just using it in a wrong way.

can somebody clarify that?

thanks!

I just have an array that runs in tandem with the instances. When I add an instance, I add an item to the array. When I delete an instance, I delete that index also from the array. The array can contain indexes, id numbers, references… whatever you need to link each instance to something else. So, if you need to get an instance for object x, you find the link to object x in the array, then the index you found will match to the instance index you’re looking for.

Hi ! Just want to mention - Alex and Ian talk about this array behavior in Training Stream around 15 min. mark

This is the same horrible method I am using in my project now, with UE4.21 - is there still no better approach to this?

Wow, at least they describe what’s going on under the hood. Probably an optimization thing, but that is probably the most stupid design I’ve seen from Unreal yet. Especially because they do not describe that anywhere. Is it really so weird to want a reference to instances? :confused:

The year is 2024 and this index issue is still same even in unreal engine 5.
I think i can find a better solution for creating not changing unique instance indexes but it seems like there is no basic solution.

Just try this:

1:When creating a instance, give it a unique method to identify later (a map variable, adding it transform to array, creating your own ID system like me)

Another method is when instance indexes changed you can change your getting instance index method too like index - number of removed indexs

I am doing a index track system so every time indexs changed, i can change my own index save methods too