Dynamic Inventory System C++

The idea is to have a dynamic inventory system consisting of AInventorable objects (Items that can be stored). These objects can be weapons that are equip-able, food to be eaten or armour to wear. The problem is that these items have allot of different spawn stats, so the idea was to create a static copy of them to get spawned later on and then destroy the instance. (AInventorable is also a replicated class, if that makes any difference)

Please note the difference between Inventory and Action bar (previously tried approaches )

Character.h:

	// AInventorable array of items to be stored in the players inventory
	UPROPERTY(EditAnywhere, Category = "Inventorable")
	TArray<class AInventorable*> Inventory;

	// AInventorable array of items to be stored in the players action bar
	UPROPERTY(EditAnywhere, Category = "Inventorable")
	TArray<TSubclassOf<class AInventorable>> ActionBar;

Character.cpp:

bool UCharacterCollection::AddItemToInventory(AInventorable * Item)
{
	if (Item != NULL)
	{
		//Finds the first empty slot
		const int32 AvaliableSlot = Inventory.Find(nullptr);

		if (AvaliableSlot != INDEX_NONE)
		{
			//AInventorable* newCollection = NewObject<AInventorable>(Item);
			//Inventory[AvaliableSlot] = Item->GetClass//GetActorClass//StaticClass
			Inventory[AvaliableSlot] = Cast<TSubclassOf<class AInventorable>>(Item);
			return true;
		}
		else
		{
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("You can't carry any more itmes!"));
			return false;
		}
	}
	return false;
}

What would my best approach be and thank you in advance.

if you think having the item still alive but hidden/disabled from simulation is a problem, i would use a sort of a UObject base store item ( lets call it UInventoryItem ) It would store the name, quantity, display icone, tool tips, a class, and a binary array

So your inventory would ben an array of UInventoryItem
About BinaryArray, look at how UE4 serialize data in internal
( spoiler : << operator A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums,Read%26_Write_Any_Data_to_Compressed_Binary_Files )

So you got 3 choices,

  1. keep items alive but hide them and pause simulation on them

2)Do specific code for each items Might sound huge work but sometimes it’s not that much, and it will save you time

  1. use a generic system like i suggested, you will learn something cool, and it will help you for you futur savegame system ! ( i suggest you to look at rama saveSystem pluggin, it’s a good one )

Thanks for the reply,
will check out your option no 3.

Watch this. Dynamic Inventory System In Unreal Engine With Only C++ - YouTube