Download

UE4 destroy my objects after 1 minute (probably UE4 bug)

Hello guys.

I made a FPS where a character has an inventory. The player starts with nothing in inventory. When the player hits a pickupble, it is added to inventory.
So, I made an interface IPickupble with a method “OnPickedUp” which will be implemented in class such as “Weapon”, “Powerups”, etc.
My inventory is a class with a array of Pickupble, and when a Pickupble is hitted, it is added to the array.
My character contain an object “Inventory” and I spawn it at the start of the level, so the character has an inventory from the start. Everything should go fine :
Character.PNG

But I don’t know why, after 1 minute (I counted the time several time), my inventory is destroyed so my character doesn’t have an inventory anymore !!! And there is no reason it should do that.
Is someone can help me? I think it’s definitively a bug from UE4.

Before :
46b9842a73566acf532d7da415e38e107c2b3075.jpeg

After 1 minute :
eea53cfa7105b562e32b8eda406f147c9b5b323e.jpeg

This is the garbage collection. Because you destroy your inventory actor right after spawnin it the variable just holds a reference to the actor not the actor itself. CHeck out my free inventory system :slight_smile:

Your actor is getting garbage collected, though I thought if you stored it in a variable it wouldn’t be removed.

A blueprint variable holds a reference to the actor not the actor.

Oh ok, so everything in Blueprint is a pointer ? Your explanation makes sense if this is the case. I thought the charateristics of the spawned Inventory were copied in my CurrentInventory variable, not referencing to the object itself (that’s why I destroy the object after my variable is set). So I have to hide the actor instead of destroy it ? The problem is my actor is still on the map , so the collision are still there. So, when collapsed, I hide the actor and then I set collisions to “NoCollisions” ? (I forgot to precise I’m a beginner on UE4 ^^)

No components in the bp? No problem :slight_smile: just spawn it at 0,0,-50000

For the inventory it can be a solution, yes (but I just hide it in the game from start, more simple).
However, when a weapon is on the map and I hit it with my character, the weapon must be hidden and and it should no longer be any collision (so no genereting a “Hit” or “Begin Overlap” event). So I cant use the “0,0,-50000” trick :smiley:

Hide it and do Setcollisionresponsetoallchannel" ignore

Yep, that’s the solution for my problems. Thanks very much man ! I own you one :wink: