Inventory Overflow Not Working - Please Help

I want to set up a 2 slot inventory that dumps out the oldest picked up item when a new item is added to the already full inventory.

Fore example:

Situation A
Interacting with an item when the inventory is empty would create a widget image of that item in slot 0 of the inventory.

Situation B
Interacting with an item when the inventory has 1 item in it would set the item in slot 0 to slot 1, and the new item would appear in slot 0.

Situation C
Interacting with an item when the inventory is full would would create a static mesh representing the item in slot 1, remove the item from inventory slot 1, then perform the steps of situation 2

My blueprint implementation is creating a static mesh of the item moving from slot 0 to 1 in both situations B and C, and is not spawning a mesh for the “discarded Item” variable I’m trying to set when the inventory length is >= 2 (situation C).

Please let me know if you need any further context, or information about other blueprints the one shown is referencing.

I haven’t looked at this in great detail, but I can tell you, you can’t can’t remove indexes while you’re processing an array, because it screws up the loop counter.

Usually, the solution is to loop backwards over the items, but in your case, removing indices inside the loop, it’s probably better to loop over one array, and make a second array as you go. At the end just assign the second array to the first.

Thanks for the advice! I’ll rework my graph to make sure the index is removed in its own loop :slight_smile:

Thanks again for your guidance @ClockworkOcean

I’m very novice with Blueprints, and have no background in coding, and you helped me get my inventory to work as expected.

Here is my final blueprint for anyone interested:

Player and PickUp Locations

Check Inventory Capacity

Handle Empty Inventory

Handle One Item In Inventory

Handle Full Inventory

Spawn Overflow Item

Now I just need to figure out why nothing is spawned every second time I pick up an item with a full inventory. I’m thinking I need to clear my discarded item array after an item is spawned. The puzzle continues!

Great :smiley: