Unfortunately you’re essentially storing UClass* when using TSubclassOf.
You could potentially use the CDO of the class type, but I have no idea if this would work well, or be at all safe:
const AProjectItem* UDB::GetItem(FString ItemName)
{
for(auto& ItemClass : ItemClasses)
{
const AProjectItem* const DefaultInstance = ItemClass.GetDefaultObject();
if (DefaultInstance->ItemName == ItemName)
{
return DefaultInstance;
}
}
return nullptr;
}
But I’d question why your inventory information needs to be an actor, rather than a simpler UObject or USTRUCT type? You could probably get away with just store an array of meta-data about the items, and only spawn the actors if you knew for sure you’d need them?