Inventory Item Stacking

Hello guys I have an inventory system with Add Item if there is no in the Inventory(Array) and if exists change the values of this item.

The only problem i have is that when the Item Exists I can’t find the item in the array and change it with the values of the hitted item(Line trace)

This is the Blueprint if the item doesn’t exist. Takes all the values and add it to the Inventory(array)

And this is the Other side of blueprint that doesn’t work …

there are several problems with your second picture.

the first issue is that your not actually doing anything with the loop. currently your only setting a inventory array element on loop complete. the next issue is your not actually using the new items information or incrementing a specific indexes qty.

anyway below is an example of how this kind of thing could be done. i did it in the pickup itself and as a function. now how this works is that i get the player so that i can get their inventory, then i run a loop which checks if there is any item in the inventory with the same name as the pickup. if the item exist in the inventory then we need to check if it stacks, if it does then we add one to the quantity and set the array element. then we set the found item bool to true and break out of the loop since found what we need. if any condition here fails then we just move on to the next item in the inventory. when all items have been checked or once we break out of the loop then the loop completed will run, at which time we check the found item bool. if the found item is true then we know we have already added the item to the inventory, but if its false then we need to add the item to the players inventory via the add node. once all thats done we can safely destroy the pickup actor.

im sure it looks complex since its a bit messy but its pretty simple, your just doing a series of checks really.

1 Like

oh and i should also note that when you try to use something like a contains node on a struct you may run into issues where all variables in the struct need to be identical to actually be “matching”. so you could have something with the same name and stackable bool but if the quantity isnt the same then it may not recognize that the array contains the item since the item is technically different.

Ok Guys I will try to change things and see if it works

Thank you Guys That worked :slight_smile: