Dilemma with Destroy Actor

Alright, so I have a fully functional inventory system, EXCEPT one simple thing…when I pick an item up off the ground and go to destroy it and place a copy/reference of that actor in my inventory, it gets deleted from my inventory after garbage collection.
So you say to me, well just spawn an actor of that class with the “Spawn Actor From Class” blueprint, but here is the dilemma…
My items that are pickable (from the ground) are a CHILD of a placeholder class, therefore that suggestion will NOT properly work out for me.
I have the code for when the item is picked up/destroyed within my placeholder class blueprint so that it affects ALL of my children (items to be pickable), so the items are essentially not able to be called from “Spawn Actor From Class.” … Does anyone have a solution I can look at?

Here is a summary.

  1. I chose item to be picked up from ground.
  2. I place actor (reference) in my inventory and set it’s owner.
  3. I destroy actor.
  4. Item is removed from inventory because all instances of destroyed actor are removed from garbage collection.
  5. I cannot find a way to use “Spawn Actor From Class” in any way to get this to work.
  6. If I start copy/pasting all the code from my placeholder class to every item in the game, that would be redundant and would not make sense to me.
  7. Any suggestions?


Anyone know how I can spawn an actor that is a child actor of a parent that is class Actor. My child object is of class “BaseItemPlaceHolder” and I can’t seem to find a way to spawn this actor because it’s not of class ‘Actor.’

This doesn’t work for some reason…this code is placed within the parent object “BaseItemPlaceHolder” which is of type ‘Actor.’

Were you able to figure out a resolution to your problem? I am currently running into the same issue that it appears that GC is eating all my item references. I am just now about to try and figure it out on my end but was hoping someone had some ideas of where to get started.

in programming term, cast a “class” does not make any sense. you can cast one instance(object) of a class to another(usually from classes that you inherited).

back to the dilemma, what I would do is:

  1. like any other games with inventory, start assign object id with unique int.
  2. in your base class, build a big Enum that contains one type of objects, multiple of them if you have different types.
    ie( 0~1000, misc items/ingredients; 10000~19999, weapons, 20000~29999 armors, etc. )
  3. have a static event that spawn item base on id, preferably from a item spawner blueprint to avoid bp compiling dependencies.
    (so if you add any new item to enums, you just recompile item class, base class, spawner class in sequence.( don’t do the castTo in base class. )

reason for not cast to child inside base.(you create real loops)

  • any change to base, you would need to recompile child
  • any castTo to non-native class, of the cast target bp changed, you have to recompile current bp that does castTo.

I managed to get the system to work, here is what I placed into the parent class.