Hi! So I’m working on this inventory system with Ryan Laley’s tutorial (specifically pt.12) and I’m having an issue where my character collects a max of 10 of an item, but when they try to collect another, instead of going on to the next slot, it replaces the 10 with 1 of the item, erasing the first 10. I would like it to appropriately move onto the next slot. Does anyone know how to fix this?
From your video, it looks like the TransferSlots function is working fine. My guess is the error might start in the AddToInventory function, or possibly AddToStack or FindSlot. Could you paste the blueprint logic for those?
I used his tutorials as well, great started but definitely requires some polishing. assuming you are querying the size of existing item stack, afterwards are you calling “add” or “add unique”
Gotcha, these are useful. Could you also add your blueprint logic for CreateNewStack?
This is just my gut feeling, but I’m thinking it might be that when an inventory slot is full, and the logic tries to create a new stack, it might be overwriting the old stack due to the wrong index.
Also, a tip: If you haven’t used breakpoints before, they’re an excellent tool to help in this situation. If you select a node and press F9, you’ll toggle on a breakpoint - it looks like a little stop sign, which will pause the program when that node is run and allow you to hover over variables to see what the values are. You can then “step” into nodes, or over nodes to follow the path of the logic. Once you’re done with the breakpoint, selecting the node again and pressing F9 again clears it.
I based my inventory in c++, but essentially I check my TMap for existing item(name variable )if it exists but the stack is less than max, I’m adding to it(if my memory is correct when calling add, and the item exists it will reset the value to the added amount so you’d want to query existing value, add new amount, then set the value to that amount. If it does exist but is at max stack, add unique. I hope this will help, I can post my code and bp if you need, though it may be a day or 2, I close then open the next couple days at work so I unfortunately won’t be in the engine again till Friday
The blueprint part of my inventory is essentially widgets, I have an inventory item widget, that receives an input of a name, queries a data table for the inventory item, sets it’s values from that on construction. Inventory item widgets are created on a for each loop in my inventory widget, that queries the TMap using functions I setup in c++, I also setup a drop system that will remove or modifykey/values, and spawn an inventory item class object in the game world
Yep, I’d recommend to go ahead a post your C++ snippet - probably will be faster to debug.
We’ll know better with the snippet, but sounds like there’s a couple places where things could cause bugs. For one, TMap doesn’t have an AddUnique() method - are you talking about an array or another data structure you have? The AddUnique() on TArrays won’t change the array if it finds an existing value - that might not be doing what you expect there either.
My inventory works fine though it’s been a few months since I finished putting it together so I can’t remember every detail about it. I will post the code and a simple breakdown as soon as I can
The Array Index should be connected to the return “Empty Index 0.”
Without that connection, this code is correctly looking at each spot to see if its empty, but when it finds one, its not returning the correct empty number.
That’s why it seems to “reset” when the 10 stack isn’t moved - it’s getting overwritten by a new 1-stack, which thinks its found an empty spot. It’s also why if you move the 10 stack to another place, it doesn’t get overwritten - because this currently only ever overwrites the very first spot in the inventory.