TArray elements disappear after a few seconds in inventory

Hi.
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)

The problem:

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

Also, I wanted to add that this problem happens even if I play in single player in the editor, so I don’t think it has something to do with replication

Can you post the relevant code?
Include the widget header and source, include the declaration of the array, and where/how you populate it, where and how you create and add the widget to the viewport, etc. You’ve described a lot of things happening, but there’s no real way to know what you’re actually doing without seeing the code.

Taking a guess here with the limited information, but it sounds like a classic garbage collection issue. Are you decorating the array with the UPROPERTY() macro?

Yes. I did.
I solved the problem. Solution below

Hi
Sorry for the late reply and thank you for replying and trying to help.
I guess I figured it out.
The reason was that, when I inserted an item into the inventory, I would then set it to hidden in game and disable collision. The idea is that the item, obviously, shouldn’t be present in the world.

The problem was that since I was disabling collision on the item itself, and not just its static mesh, it would delete the item from the world.
Weird that I was still able to reference it from the inventory class, but that’s pretty much the reason.

I solved it by disabling collision and hiding the mesh component, instead of the item itself.

Thanks for your replies.