Hi, I’m having a problem showing items in inventory. I use datatable, but can’t figure out where is the problem, I put some print string and it appears in the comlpeted for each loop, but items won’t add in inventory. Can someone help me ? Thank you very much for your time.
Hi,
In your 2nd screenshot, the Make Struct Inventory Entry has no Item ID (None). So if the item you are adding already exists in the inventory, the Get Data Table Row won’t find it (3rd screenshot) because its ID is set to None. Not sure if this is the issue in your case, but you should probably fix this anyway.
The Set Array Element node expects you to provide a full struct. It doesn’t modify the existing one, it overrides it completely. In your 2nd screenshot, you are basically replacing the existing item by a new one with no ID and a Max Stack of 0.
If the only thing you want to edit is the Quantity, I suggest you use an array Get (by ref) and then a Set Members in Struct node. The Set Member in Struct will only edit the variables you enable. This will only work if you use the Get (a ref) for the source array, and not the Get (a copy).
Alternatively, you can still use you current setup but you will have to provide values for all variables of your struct.
As a side note, if you don’t want any duplicate item in your inventory, you can also take a look at using maps instead of arrays. This will avoid you having to loop through the whole array to know if the item exists already.
Thank you very much for your answer, probably I’ll go with maps because even If I get Item Id and printed item added, I can’t see it yet in the inventory… Thank you for your time, I’m tryng to develop a small dungeon crawler.
You should use a Print String node out of the Row Not Found pin from the Get Data Table Row node (3rd screenshot), just to debug whether the data table is finding your item in the first place.
Also, I just noticed you were using a Uniform Grid Panel widget for your inventory item. Uniform grid works by using Row and Column indices. What might be happening is that your new widget is correctly added to the grid, but all item widgets are stacked on top of each other (at the same row and column). You can try it in the editor directly by dropping new widget to the grid panel: they all stack on top of each other, you have to select them and use the arrays to move them to different columns/rows.
Instead of using Add Child (3rd screenshot), use Add Child To Uniform Grid, it will let you set the row and column of the new widget directly, to make sure it doesn’t overlap with an existing one. This means you might need to update your logic to manage all items of your grid.
If it’s a classic inventory system, I imagine you can create all the slots widgets from the beginning, in the editor, and just update the slots when an item changes, instead of creating a new one.
I’ve never done an inventory system like this so there are surely some best practices and tips, many game use this. Maybe someone else with more experience can chime in.