How to create item specific inventory slots?

Hey Guys,

I’ve succesfully created a UMG inventory system loosely following the tutorial series here but this is setup so that each piece of inventory you gather goes into the first available bag slot. How would I modify this to create a specific slot for each unique item? Eg. a ‘canned beans’ slot, a ‘banana’ slot, etc? It is safe to assume that I would only have one instance of each inventory type available for pickup, so there would be no ‘stacking’ or duplicate items.


It depends how your inventory is built. For example, if each slot is a widget, you can add a variable “ItemType” in with an int value and same in item blueprint. When item is added you loop with break widgets and add item to the slot having the right value, and if no values then add it to a global inventory slot.
To stack, you add another int in widget and when add item you set value = value + 1 and value = value -1 when you remove it with a check value = 0 to no more be able to remove item.

Edit : instad of loop, you can have an array of your widgets too if you dynamically created them and by setting itemtype the same value as widget array index, using it to set item with a “set element”

Hi Fen,

Thanks for the response. I’m very new to UMG and trying to remember this all from work, so if this doesn’t make any sense, I can take some screenshots when I get home. :wink:

Currently, I’ve got a single ‘Inventory HUD’ widget, which has a uniform grid panel in it that is divided up into 120 unique inventory slots. Within that widget and panel, I’m calling my ‘Inventory Slot’ widget 120 times. My ‘Inventory Slot’ widget does have an ‘Inventory Slot Number’ integer variable, which is unique for each of the 120 slots within the panel.

Would it be possible to somehow use that ‘Inventory Slot Number’ variable to do what you’re describing?

Yes, this is this value you will use. You set an int with the same value in item blueprint and when you add it to inventory :
if you haven’t set your widgets in an array : you do a “get all widgets of class” with inventory slot widget class selected. From “found widgets” you do a for each loop with break. From “array element”, you get your “inventory slot number”, you check that it is = dragged from item “inventory slot number” / branch : true : set item in slot and link to break to exit loop.

If you have an array, you simply “get” your slot from array, using the value as index (assuming you have arrange widgets in the right order when you create array, for example on event construct make array with all widgets added in right order (yes boring, why doing a procedural can be cool : you do loop : create widget, set index with loop index set it in uniform grid (using row and column) and add it to array) then you set item in this slot as before. Big advantage is that you avoid the loop which can be huge as you have 120 slots.

both will work the same with a stack, you just have to add another int for quantity.

If some items have no particular slot, you’d better separate if you loop but if you have an array, you just set a “free” value like last value + 1 and do a branch before loop, if value = free value, then you set item in free inventory, if not then you get value from array.