I have an actor that spawns actors that spawns actors. Here’s the easiest way to look at it
Game
- Category
- Item
- Category
-
Item
-
Item
-
Item
-
Item
- Category
-
Item
-
Item
-
Item
Game has an array of categories and Category has an array of Items. Simple enough. One more note, when an Item is created, I also save a variable of type Category to tell it what Category it belongs to.
For the most part, the Game is running a “For Each” loop across a category, getting the items, then “For Each” item (under the right conditions), it generates a new category. So when the nested “For Each” loop ends and it goes back to the loop for categories, there are new entries and they get processed as well. I say this because, until now, I have not had a need to reference a specific item or category - I simply process them all in order.
I’ve come to the point where in some scenarios, adding an item to one category means I need to remove an item from a different category. Referencing another category/item has become difficult.
There are two ways to remove something from an array. Either by “item” or by “index”. In my case, I have no idea what the index is, so I tried “Item”.
Using my list from the top of this post, let’s say I’m in the second category. I get to the last item which manages to find another item (that will need to be removed). The found item is actually the THIRD item in the last category array. I use the found item’s “Category” variable to get the category that found item belongs to. I then get the array of items for that category, run the “Remove Item” function on it, passing in the found item.
This SHOULD remove the THIRD item in the array, but instead it removes the FIRST item in the array. The Remove Item function doesn’t seem to check anything other than the actor type so it doesn’t care which actor is removed. It looks at the array and says “Yep, Item at index 1 is an item. Removed. Done”
NOTE: Items are removed as they are processed, so removing an item in the way described above is my way of saying “This item no longer needs to be processed”. In saying that, I can’t be certain when I get the Item’s category from the variable, I can’t be certain it’s going to the correct one (if Item doesn’t get the correct one, why would Category?).
So, if I can’t use “Remove Index” because I don’t know what the index is and I can’t use “Remove Item” because the blueprint doesn’t know what the item is, I need to find a unique identifier to the Item actor. Then I will loop through the Category and check if the unique identifier is the one I’m looking for. If so, “Remove Index” of the Item array on the index I found. I have found the actor “Display Name” which looks good (and I’d be happy to use it as a unique ID) but the tool tip specifically says it should not be used to uniquely identify actors. Is there anything else I can use?
If there’s nothing else, I will need to come up with a system to generate unique identifiers myself, but I wanted to check here first.
Wow that post was much longer than I had anticipated.
TLDR:
When you run a “Remove Item” on an array, does it just remove the first item that matches the type? (mine seems to)
Is there a unique identifier generated for actors I can reference (Similar to “display name”)?