# Array Index not deleting in inventory system

**URL:** <https://forums.unrealengine.com/t/array-index-not-deleting-in-inventory-system/472895>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [October 14, 2020, 4:41am UTC](https://forums.unrealengine.com/t/array-index-not-deleting-in-inventory-system/472895 "2020-10-14T04:41:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![trustissu3s](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@trustissu3s](https://forums.unrealengine.com/u/trustissu3s)\
**Post date:** [October 14, 2020, 4:41am UTC](https://forums.unrealengine.com/t/array-index-not-deleting-in-inventory-system/472895/1 "2020-10-14T04:41:25Z")

</div>

I am building an inventory system in unreal. Theoretically, if you right click on an object in your inventory, it spawns in front of you and is removed from your inventory. This works fine. However, when the player reopens the inventory, the item reappears and can be dropped again, effectively duplicating the item. I added a print string to test that the function removing the array element was being called, and it is being called. any idea what I’m doing wrong here? thanks.

 ![318619-capture3.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/2/a/82a652d4301ebd3ce7297227d4ee8bfb314cd7a9.jpeg)

---

<div class="post-metadata">

**Author:** ![Kehel18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Kehel18](https://forums.unrealengine.com/u/Kehel18)\
**Post date:** [October 14, 2020, 6:02am UTC](https://forums.unrealengine.com/t/array-index-not-deleting-in-inventory-system/472895/2 "2020-10-14T06:02:52Z")

</div>

Hi! There can be several issules:

- check that SlotIndex is correct and is in range
- if Inventory is struct check that you do all by reference

---

<div class="post-metadata">

**Author:** ![ClockworkOcean](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/clockworkocean/32/1169999_2.png) [@ClockworkOcean](https://forums.unrealengine.com/u/ClockworkOcean)\
**Post date:** [October 14, 2020, 11:10am UTC](https://forums.unrealengine.com/t/array-index-not-deleting-in-inventory-system/472895/3 "2020-10-14T11:10:56Z")

</div>

I’m noticing two strange things:

1. When you spawn, you don’t use the current index. How do you know what to spawn?

2. In refresh slot, when the quantity is \> 0, surely you need to decrement it?

---

<div class="post-metadata">

**Author:** ![trustissu3s](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@trustissu3s](https://forums.unrealengine.com/u/trustissu3s)\
**Post date:** [October 14, 2020, 7:25pm UTC](https://forums.unrealengine.com/t/array-index-not-deleting-in-inventory-system/472895/4 "2020-10-14T19:25:18Z")

</div>

1. I have a class for the item structure in the base item, that all items are connected to.
2. I had the \<=0 to check to see if the item is really in the players inventory, but it is overall unnecessary in deleting the item.

thanks. c:
