Hi,
For my inventory UI, I want to have the player to have 32 inventory slots.
To achieve this I have a WrapBox setup that iterates first over the inventory Item’s array and creates the slot widgets for each item. After this I add (32- items in inventory) empty slot widgets to give the appearance of empty spaces in the inventory.
The issue is that on each inventory update (picking something up, dropping/using an item), I need a performant way to update this ItemSlot list in the WrapBox.
I’ve played around with a uniformGridPanel and a WrapBox but it comes down to the same thing (not taking into account the row/column calculations for the grid).
I’ve found 2 ways to accomplish this, but neither of them really seem performant. (I also notice an fps drop when updating the inventory array).
On each inventory update:
- The current way I’m doing it now:
Clear all children of the wrapbox / UniformGridPanel.
Create slot widgets for each item in the inventory array and add them as child.
Then create x empty slot widgets to have a total of 32 slot widgets. - Instead of deleting 32 widgets and create 32 new widgets on each inventory update, start with 32 empty (no data) slot widgets, then iterate over the inventory item array and use the WrapBox.GetChildAt( index ), then Cast it to a slot widget and then use a function to pass the item data to it so it’ll show the icon etc. Also I’ll also need to make sure to empty widgets that could have item data in them. So It’ll be always 32 casts.
So it’s a choice between widget creation or casting…
Is there maybe a better way to do this?
I’m doing this in C++, but I’m open for blueprint info as well, since it’s more of a logic kinda thing.
What is the standard way of doing this? I’ve looked at a ton of tutorials, but they never seem to really think about it.
Thanks to anyone that could shed some light on this.
-Nick