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.