I’m trying to code an inventory and I want to store a reference of a blueprint based on a C++ Class. As the Blueprint will be duplicated and be the different “items” a player can pick up. I also want to store the object type, not a pointer reference to a spawned actor, as I want this to work cross levels etc.
Pseudo code:
this->ActorClass = thisBlueprintIsOfType;
Here is what I currently have:
public:
// Actor Name
UPROPERTY(BlueprintReadOnly, Category = Pickup)
FString Name;
// Actor Image
UPROPERTY(BlueprintReadOnly, Category = Pickup)
UTexture2D* Image;
// Actor Class
UPROPERTY(BlueprintReadOnly, Category = Pickup)
UClass* ActorClass;
// Insert Image
void UpdateInventoryObject(ATestActor* actor);
And the update function, the last variable assignment is obviously wrong:
void InventoryObject::UpdateInventoryObject(ATestActor* actor)
{
this->Name = actor->Name;
this->Image = actor->Image;
this->ActorClass = actor;
}
I’ve tried
UPROPERTY(BlueprintReadOnly, Category = Pickup)
TSubclassOf<ATestActor> ActorClass;
But I’m not sure how to store that value in the function. TSubclassOf seems to be what I want thought if there isn’t a better way.