How to get the index from an array element?
I'm making the targeting system for a turn based RPG and would like to get an element index in integer form, so I could check who's selected and stuff like that. Is it at all possible, or do I need to create an integer and manage it all the way through?
asked Sep 09 '18 at 09:15 PM in Blueprint Scripting
No, because TArray same as raw C++ array is using memory offset as index, making it unreliable id, if you remove element from array it will move all farther items in memory in direction of removed item. You might consider using TMap which use key to value pairing (TPair) to store items and you can use any type as index, at first it might not make sense to use integer as key type as it will work like TArray, but thing in TMap set index will be persistent or else you will change index of the item yourself
answered Sep 09 '18 at 09:46 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here