I want to get index of selected mag, and when this function is called again, loop should start from next index.
My problem is, I really don’t know how to do this.
instead of a ranged for.
If you have an index stored on AShooterCharacter, you can start the loop from there instead of 0.
You could also take that index as a parameter and return the found index for the caller to store instead. Storing the variable in AShooterCharacter could be a problem if different arrays of items are passed in.
Well, in your case since the items in the array are pointers you should be able to use either of the Find functions provided by TArray. One returns the index (and returns INDEX_NONE if it’s not found) while the other returns a boolean and has an int& param you pass in to be filled out with the index (which can be treated as valid if the function returns true).