I need to load the following Blueprint class into the level at runtime without using constructors. This is done to spawn an actor (Metahuman in this case) at runtime when a user presses a key on the keyboard.
The blueprint callable code for this is as follows
header
UCLASS(Blueprintable)
class FACEANIMATION_API UMetahumanUtil : public UObject
{
GENERATED_BODY()
UFUNCTION(BlueprintCallable, Category="Metahuman")
static void SpawnMetahuman(AActor* CurrMH);
};
implementation
void UMetahumanUtil::SpawnMetahuman(AActor* CurrMH)
{
UE_LOG(LogTemp, Warning, TEXT("Spawning metahuman"));
FString Path = "/Game/Metahumans/Aoi/BP_Aoi.BP_Aoi_C";
UObject* SpawnActor = Cast<UObject>(StaticLoadObject(UObject::StaticClass(), nullptr, *Path));
UBlueprint* GeneratedBP = Cast<UBlueprint>(SpawnActor);
UClass* SpawnClass = SpawnActor->StaticClass();
UWorld* World = CurrMH->GetWorld();
FActorSpawnParameters SpawnParams;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
FVector Loc(-60, -10, 40);
FRotator Rot(0, 0, 90);
World->SpawnActor<AActor>(GeneratedBP->GeneratedClass, Loc, Rot, SpawnParams);
UE_LOG(LogTemp, Warning, TEXT("Spawned metahuman"));
}
This will be used in the level blueprint as follows

This is not working because GeneratedBP variable is null.
I was hoping to get some pointers on how to do this. Most of the questions I came across on the forum use constructors for doing something similar.
Thanks.
