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.
answered Mar 07 '19 at 04:05 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here