Load a TSubclassOf at runtime ?

I has class AMyActor

UCLASS()
class ANSWERHUB_API AMyActor : public AActor
{
	GENERATED_BODY()
}

it is BP inherit from AMyActor

293492-111.png

Next, load the path into TSubclassOf

	const FString MyActorBpPath = "/Game/Test/NewBlueprint.NewBlueprint_C";
	TSubclassOf<AMyActor> MyActorClass = LoadClass<AMyActor>(GetWorld(), *MyActorBpPath);

	UE_LOG(LogTemp, Warning, TEXT("Class Name is %s"), *MyActorClass->GetFName().ToString());

it is the log:

293493-1345.png

1 Like