I’m experiencing some rather weird problem within my project.
I’m building an inventory system (C++, based off third person template, UE4.13.1 compiled from github).
Here’s my setup.
I have a class based off on actor component, which is the inventory itself. It holds the array of items, and all kinds of functions to access the inventory.
I add this class to my third person character (in c++)
I also have another class, called InventoryWidget, which is the c++ base class for the widget blueprint itself to display the items.
I attach the widget directly to the player character, and then give it a reference to the inventory component.
Within this blueprint, I have a function that iterates over the array of items from the inventory, and displays them (which it can access because as I said, when I add the widget to viewport, I also give it a reference to the inventory component)
When I add an item to the array by assigning a pointer to that item within the array (which is done on the server, independently of the widget), this seems to work fine.
If I try to debug it, by iterating over the array and listing all the items, everything works. The items are there.
However, the widget only shows my item for a few seconds:
When I add an item, if I quickly open my widget, it’ll show the item where it’s supposed to be, however, If I reopen the widget after say… 3 seconds, the item is gone. - Again, the array still contains it, and if I iterate over it inside of the player character class, or the inventory component class, clearly the item persists, but the widget somehow stops seeing it after a while.
It doesn’t matter if I open the widget several times, or once, or not even once. The item still shows for 2-3 seconds even if I quickly open and close the widget, similarly, if I insert an item, wait for 10 seconds, and then open it, the widget is empty.
Is it possible that this array is somehow getting garbage collected? If so, why only for the widget?
Any hints, links, directions, whatever, as to why this could be happening would be greately appreciated.
Thanks in advance