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.
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.
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 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.