Inventory system array issues

Hey, so I am making a inventory system that has 3 slots. each slot can be filled with 1 item. I currently have it setup that when you pickup a item it will check if the current selected slot is empty, if it is it will add the item. Same thing with removing bassicly it checks if there is a item in the slot if yes then remove.

Currently I use a array to hold the items there are in the inventory but when I remove for example the item at index 1, the item that is on index 2 will now go to 1. How can I make it so that the array has 3 slots and dont move items arround when the index below them is empty.

ss2

Thank you, if you need some more info or know a better way to do this than please let me know.

Why not just use 3 vars? You can then use ISValid to determine if the slot is empty or not.

This is the normal behavior of an array, you’ll need to use another method if you want to accomplish such a thing.
I agree with Rev0verDrive, you could simply use three variables.

If you want to use something that can easily be expended, like an Array, I’d recommand using a Map with number as Key and your Item as Value.
Here’s an example, I’m using an Actor as a value instead of you item.
help 1

I can add actor to this Map easilly. Here I’ll just spawn some actors in my level as a example to add things to my Map. And I’ll set each actor to a specific number.

And I’ll add a keyboard event to remove the first actor in my map.
help 3

I’ll also add a small PrintMap function to print if the Key 0 or 1 has a value. I’ll call it at the Begin Play and after pressing L.

And here’s my Output Log. When I spawn, I have an actor on Key 0 and Key 1. Right after that I press L.
And see, I no longer have an actor attached to the Key 0, and the one attached to Key 1 hasn’t moved.
help

Hope it’ll help :grinning: !

2 Likes

Thank you this works great. I though the map was something different but this works great.

1 Like

Because I want to keep it a bit more modular in case I want to use more or less slots. But yes that would be a viable solution.

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