Remove from array is not working

I don’t know if this is a bug or I’m doing something wrong.
I have a struct list that stores which characters follow which. I can add to this struct but when I try to remove characters, it only removes half at a time.

This is the code:


The struct is “Follow List” and is just an array of 2 actors. The struct takes in the “Leader” and the “Followers” like so:

Leader 1 | Follower 1
Leader 1 | Follower 2
Leader 1 | Follower 3
Leader 2 | Follower 4
Leader 2 | Follower 5

And the idea for stopping the followers from following was to remove the leader entries.
But for some reason, it only removes half of the entries at a time.

The way I’m working around this is by running it 5 times in a row.

Is this a bug?

You should remove elements in reverse order.

My Products

3 Likes

It is not a bug, you cannot remove an item that is in the middle of an array, when you remove an item, what the array does is reorder the IDs, for example id1=A, id2=B, id3=C, Id4= D, if u remove “B” now u array is id1=A, id2=C, id3=D

If you want the Id to be permanent and you don’t want these problems, you can use a dictionary that in unreal engine is called “MAP” or delete from the last Id

3 Likes

Ok thank you, I didn’t realise that it worked like that :sweat_smile:

I have the same problem but with CLEAN. I tought when you clen an array, it’s empty.