Swapping Variables in Array (index location)

Hello! I am trying to figure out the best process for swapping “items” (BP_Actor) in an array. I have an array were items are inserted at an index location. What I want to do is perform a “check” at that index location to see if there is already something there, and if so, remove that item at that index location and replace it with the new item. So should I be using “Is Valid” before the insert and then if Is Valid is true, remove index at location?

In addition to the above:
I’ve noticed that if I have an empty array, and I use “Insert” to insert an item at a certain index location. (so now the only item in the array is at index 4) If I attempt to “remove” the item at that index, it only moves that item’s index down by one… So then, the item at index location 4 then moves to index location 3. Do I need to first insert that item to the other array and then delete the actor?

Any help is appreciated!
Matt

Well, if you have an array of lets say 20 items, the first 20 will all be valid; if you do not know if the array is as long as the index you are trying to access, then you will need to check array length, and if length is less than index you want, you know that it is not valid. I don’t think ‘Is Valid’ works with arrays anyways. You could just make a temp variable, for example: ‘Temp Index’ (int). And you could do this:

set ‘Temp Index’ to the 1st index.
set the 1st index to the 2nd index.
set the 2nd index to ‘Temp Index’

Okay, I see what you are saying. Let me explain what I am doing.
I have two arrays: “Inventory” array and “Equip Inventory” array.

Inventory array items are "ADD"ed at the next index location
Equip Inventory array items are "INSERT"ed at a given index location.

All item categories have an assigned index location:
Hat=index 0
Shirt=index 1
Pants=index 2
Shoes=index 3

Using the “INSERT” works as expected. So that means that I could have my “Equip Inventory” completely empty all but an item sitting at index 2.
index 0= none
index 1= none
index 2= Cargo Jeans
index 3= none

I want to add an item to the “Equip Inventory” at given array index, and if there is something in that given index, return that item to the “Inventory Array”.

Sorry for the long explanation.

Any addition advice would be lovely!
Thanks,
Matt

I think the node is called ‘set array element’. You could try that but I think it works very similar to just the insert node.

Yes, I’m guessing set array element has to do less work or something.

Wonderful! Thank you gents for the replies. I am actually already using “Set Array Elem” and not “Insert”. My problem is that when I remove the index from my “equip inventory” the item is not removed but only moved down 1 index. This could be because I need to implement some type of “Base item place holder” to fill the array…? As Jamendxman3 said previously. Is that correct?

Also, how can I check to see if there is an variable at a certain index location?

Just get item at index, and if it either isn’t none, or the length of array is higher than index, it has a variable.