How do i remove an index from array without affecting other items?

So i have this inventory code, where if i pickup an object, it adds the array by 1. For example; when I pick up a book it sets the array to 0, when I pick up a key it sets the array to 1, when I pick up a battery it sets the array to 2, so on and so forth. And i wanna have a feature to drop any item to give space for other items.

So the current code i have is whenever i press the ‘drop’ key, it spawns the item from a certain location, and removes the icon from the inventory UI. The problem arises however is i want to remove this item from the index, lets say i want to remove the key, so the desired result should be; index 0 = book, index 1 = none, index 2 = battery (the index 1 should be none so whenever i pick up a different item it works perfectly. However when i use array remove index, it instead becomes; index 0 = book, index 1 = battery.

And i could use Set Array Elem and set the item to none, but that instead makes it so whenever i pick up a new object, it would be index 0 = book, index 1 = none, index 2 = battery, index 3 = new item.

Is there any way to do as title suggests?

1 Like

The ADD node always puts the item on the end of the array, you need to use SetArrayElement, to put the item in slot 1 :slight_smile:

I see, but how do i make it check so that if the next array element is null (or empty) it only does that set array elem node?

For example: index 0 = book, index 1 = none, index 2 = pen; how do i make it as such so that it checks what index next is free / null and it adds to that index?

Yeah… You have to write that bit manually :wink:

what do you mean by that?

There’s no node to do it for you.

You have to run down the array looking for a gap. If there is a gap, overwrite it, if not, add to the end.

1 Like

apologies for the late reply, i tried doing different stuff out, but i never managed to find how to find for a gap in the array, do you use the is valid index or a different node?

1 Like

If you’re setting the array element to none when an item is removed, then you can find the empty slot like this

this is assuming you have an actor reference, and an array of actors.

ahh i see, that works but still a few errors in my code, thank you very much nonetheless

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.