How can I make a callable function for a C++ class without initiation?

Hey all,

I am trying to create an AInventoryItem that will have a virtual function its children will call and override. The end goal is that each item made for the game will have its own unique UseItem() function but it can be called without creating an instance. I understand that functions can be made static, which makes them callable without an instance, but static functions cannot be virtual.

I am trying to avoid spawning an item to use its function, turning off collision and visibility, and then destroying it when its effect is complete. I know UE4 automatically deletes objects that go so far out of range. I want to avoid littering the game with a ton of invisible items and I don’t want anything to be auto-deleted before completion (Say an elixir that lasts for an hour).

Does anyone know a simple way to reconcile this issue?

Thanks in advance.

I think encapsulating the item in a struct or UObject is the way to go. Have everything that needs to be available at “inventory time” be available.
Only spawn the item when you really need it.

That is how I implement my inventory stuff most of the time.

All of the item data (icon, quantity, stack size, class) is in a struct. I just don’t know how to use the item ( AInventoryItem::UseItem() ) without spawning it first

There is no real way, you can make UObject for that though, so instead of spawning an actor, just use NewObject() if you need call functions.
You can also use a spawn UObject instead of a UStruct to give the DataContainer some real logic and override it for each item.

Does it specifically need to be a UObject or can it be a child of a UObject such as AActor? I would assume AActor still can call NewObject() since it is a UObject but I just wanted to make sure.

It should be a UObject, since Actors has to be spawned, you can use AActors just fine though. Just no need to use AActor for something that doesn’t “live” in the world.