Download

Keeping inventory synced (Fixed thread)

Hello.
I am relatively new to Unreal Engine ( around ± 10 days , however I already found that if I try to write an apostrophe here on the forum, it somehow posts the thread :smiley: ). I have used to program in some different IDE. I am currently trying to do a pretty simple inventory that is just a list of items. I have watched some tutorials from PyroDev, but I have found an error in it (and yes, it is even in his final product showcase). The error is that if there is any change in the inventory array while the inventory UI is open, the list in the UI is not updated.
That makes sense because in his tutorial he gets and creates the list just on the widget initialization. So I have added the part that populates the list into the EventTickEvent.
Of course that this would create even already existing items every tick.
A solution for this that I used in Unity or Eclipse for this is clearing the list every time before populating using clear children, but for some reason when I do it, the list seems to be never populated.

Thanks in advance.

You could force an full item UI refresh each time after adding a new item. Although I would advice only refreshing the item being added. Setting up your system this way. Meaning when you use drag and drop for example, set an item reference inside the slot you drop on, and refresh said slot.

I haven’t taken a look at the tutorial, but if your items are contained in an item slot object, you can store a reference to the item slot in your item slot widget.

I haven’t seen the tutorial, but updating the inventory on every tick is a bad idea. It will definitely destroy your performance.

You should keep everything event-based. Just update the inventory whenever something changed in it it (For example, when you use an item, pick up a drop, etc).

Oh, so I should have reference to the UI somewhere in my character and then if is something changed, call the update? I will try it right now. Thank you very much!