Prevent garbage collection for item in inventory

Hey everyone, I am pretty new to unreal. I want to pick up my item and add it to the player inventory after that remove the item from the world. But I don’t know how to keep a valid reference so the garbage collection doesn’t try to delete it after I call “Destroy Actor”. An idea was to just hide the item but that seems more like a workaround and not a solution.

Item Actor BP:


FirstPersonCharacter BP:

Inventory Widget BP:

Thanks in advance.

Don’t add the item itself. Add a struct that encompasses the items traits. Then destroy the item.

Each item should have this struct inside of it. It can have the name, effects, sell cost etc.

Got it! Just learned what structures are. Thanks a lot

if the item is in your inventory then the inventory has a reference to it so it wont be garbage collected right?

i prefer objects over structs for inventorys, much more modular, in saying that you still need a struct for saving/loading

Well, I added the reference to the array and destroyed it after because I didn’t know how to do it otherwise. I got it working with the struct now tho.

Can you explain how I would do it with the reference? And what would be the benefits?

I was referring to Uobjects I think you’re using actors. if you wanted to use actors you could just hide/disable collision instead of destroying it but that could be expensive if you have 100s of items.

the advantage of objects is they’re modular, you can have a weapon item and an armor item with difference variables for instance, you can also run code on objects. so say a weapon has ammo i handle reloading on the object itself