I’m trying to create an inventory system similar to the one in the Souls games where you have different inventory pages for each item type (weapon, consumable, …etc)
I made a system trying to replicate that and it worked great for all item types except the consumables since they’re the only items that stack I had to make something different for them so I made this
It worked great at first but I noticed an issue when picking up different kinds of items the add quantity section only adds to the last created slot eg: if I pick up 5 apples in a row and then 5 of any other item it works fine but if I were to pick up 2 apples 3 of the other item and then 3 apples it adds the last 3 apples to the other item slot
I know it’s a little bit confusing and not the ideal way of doing this but I’ve been scouring the internet trying to find a way to do it correctly and all of the tutorials I found either use a set amount of slots and search through them as an array which won’t work with me since I want an “infinite” inventory or they use a system that won’t work with my category pages system
I’m relatively new to the engine and trying to figure out these sorts of things with my limited knowledge can be quite frustrating so any help would be appreciated
feel free to ask me to provide more information if you need
P.S: I kinda already identified the problem from what I understand it happens because there’s no way to tag widgets with unique IDs or something similar so all the slots are considered the same thing regardless of what item they’re holding
So when I need to add the item quantity to the already existing slot I need a way to tell the game which slot to add to
I can’t find anyway to do that since all the slots are the same if only there was a way to tag each slot with a specific id that could fix the issue
for this sort of troubleshooting you just got to break down the execution flow and go through step by step to see exactly what is happening. You can also add a print log to the beginning of each function with a description of all the incoming arguments, and also do this anyhwere important values change. Then after playing you can read the output log and usually then the problem spot will be very apparent.
You could start by putting a breakpoint on this function, then you can hover over the function in blueprint and unreal will show you all the inputs. verify everything and then you can step through through one node at at time from there. That is the quickest thing to do but if it’s a complicated system already, I think taking the time to log each part of it will pay back in the long run.
If the inputs are coming in wrong then you know that you need to set a breakpoint somewhere sooner and see what is going on there.
This might help me but not a lot since I kinda already identified the problem from what I understand it happens because there’s no way to tag widgets with unique IDs or something similar so all the slots are considered the same thing regardless of what item they’re holding
So when I need to add the item quantity to the already existing slot I need a way to tell the game which slot to add to
I can’t find anyway to do that since all the slots are the same if only there was a way to tag each slot with a specific id that could fix the issue
Well the first thing I did was put your question into chat gpt to try and figure out where the question is. You’ve attached a ton of extranneous info that is not pertinent and has to be filtered out.
Now you are adding a bunch of info that wasn’t in the first post but is relevant. So it looks like the question is not “souls like inventory system” but rather, “how can I ID a widget instance?”
There are ways to identify widgets - you can make an instance editable variable and populate it when the widget is created. Therefore, for instance, if you want to associate a widget with some actor, you can pass that actors reference in when the widget is created.
Not only are there too many ways to make a widget ID system, but there’s probably no need to do so in this instance, not in a traditional sense at least:
associate enumerators with widgets directly instead:
And Find what you need by item type, add X amount to that thing. It would work for any number of types but handling a list of 100 enums is not what I’d recommend sober.
You are already using a map but in a somewhat rigid way. You associate Name + Quantity. What I suggested is a direct association of item type and the actual widget instance. This way you can take advantage of Find to return the pertinent widget.
The red frame is where you’d add the does it already exist query. The Begin Play loop is probably redundant. Useful if you want to populate containers upfront.
If you need to differentiate between 100s of types, you may need a real ID system. It could be as simple as Name with neat naming conventions, but an int would suffice, too. You should still use the abovementioned map for this, it finds things instantaneously without looping over 1000 of items.
And this is even before we start talking about Named Slots - consider looking into how these work, they allow for highly modular and decoupled designs.
Think of them as true item agnostic slots. A slot that fits any user widget; you communicate with the slot and the slot handles any widgets it hosts. This bad boy: