# Inventory system array issues

**URL:** <https://forums.unrealengine.com/t/inventory-system-array-issues/1903512>\
**Category:** Blueprint\
**Tags:** arrays, inventory, inventory-system, unreal-engine, Array, Blueprint, question\
**Created:** [June 14, 2024, 9:37pm UTC](https://forums.unrealengine.com/t/inventory-system-array-issues/1903512 "2024-06-14T21:37:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![DonJuan1232](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonJuan1232](https://forums.unrealengine.com/u/DonJuan1232)\
**Post date:** [June 14, 2024, 9:37pm UTC](https://forums.unrealengine.com/t/inventory-system-array-issues/1903512/1 "2024-06-14T21:37:34Z")

</div>

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.

 ![ss1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/e/d/2ed54f2bc1400215f48b4d91c9ee8c8aaf6a6bcf.png)

![ss2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/0/c/b0c44d9328b481a590aa0d5ba892bdad3468ce9f.png)

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

---

<div class="post-metadata">

**Author:** ![Rev0verDrive](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rev0verdrive/32/907214_2.png) [@Rev0verDrive](https://forums.unrealengine.com/u/Rev0verDrive)\
**Post date:** [June 14, 2024, 11:02pm UTC](https://forums.unrealengine.com/t/inventory-system-array-issues/1903512/2 "2024-06-14T23:02:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Voxiit](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/voxiit/32/1217475_2.png) [@Voxiit](https://forums.unrealengine.com/u/Voxiit)\
**Post date:** [June 14, 2024, 11:41pm UTC](https://forums.unrealengine.com/t/inventory-system-array-issues/1903512/3 "2024-06-14T23:41:51Z")

</div>

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/7/6/f7634fd2f85a5405f858468efa586d004d3f7762.jpeg)

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.

 ![help 2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/f/1/5f13f1da67d56d420b28256276c1dcc33b0de9aa.jpeg)

And I’ll add a keyboard event to remove the first actor in my map.  
 ![help 3](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/b/4/6b4843f71898798e19bcb06d4bfd89522a79df88.jpeg)

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.

 ![help 4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/d/8/fd840052ace2aea2ac522a5b706f9c3fc011f40f.jpeg)

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](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/3/4/234e952aab6e068f474c519d8acb54b82b6a7834.jpeg)

Hope it’ll help 😀 !

---

<div class="post-metadata">

**Author:** ![DonJuan1232](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonJuan1232](https://forums.unrealengine.com/u/DonJuan1232)\
**Post date:** [June 15, 2024, 7:07am UTC](https://forums.unrealengine.com/t/inventory-system-array-issues/1903512/4 "2024-06-15T07:07:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DonJuan1232](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonJuan1232](https://forums.unrealengine.com/u/DonJuan1232)\
**Post date:** [June 15, 2024, 7:08am UTC](https://forums.unrealengine.com/t/inventory-system-array-issues/1903512/5 "2024-06-15T07:08:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [July 15, 2024, 7:08am UTC](https://forums.unrealengine.com/t/inventory-system-array-issues/1903512/6 "2024-07-15T07:08:48Z")

</div>

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