# Loading blueprint class into level without constructors

**URL:** <https://forums.unrealengine.com/t/loading-blueprint-class-into-level-without-constructors/602737>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [July 12, 2022, 1:20am UTC](https://forums.unrealengine.com/t/loading-blueprint-class-into-level-without-constructors/602737 "2022-07-12T01:20:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcs\_032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mcs\_032](https://forums.unrealengine.com/u/mcs_032)\
**Post date:** [July 12, 2022, 1:20am UTC](https://forums.unrealengine.com/t/loading-blueprint-class-into-level-without-constructors/602737/1 "2022-07-12T01:20:40Z")

</div>

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.

 ![Screen Shot 2022-07-11 at 6.13.18 PM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/e/7/8e772a20452d328a648f2c58136e7b45c4b40473.png)

The blueprint callable code for this is as follows

header

```nohighlight
UCLASS(Blueprintable)
class FACEANIMATION_API UMetahumanUtil : public UObject
{
    GENERATED_BODY()
    
    UFUNCTION(BlueprintCallable, Category="Metahuman")
    static void SpawnMetahuman(AActor* CurrMH);
};

```

implementation

```nohighlight
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  
 ![Screen Shot 2022-07-11 at 6.17.50 PM](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/4/9/2498f3a85cf5623864d27b333e042a00e55997a2.png)

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.

---

<div class="post-metadata">

**Author:** ![mcs\_032](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@mcs\_032](https://forums.unrealengine.com/u/mcs_032)\
**Post date:** [July 12, 2022, 6:43am UTC](https://forums.unrealengine.com/t/loading-blueprint-class-into-level-without-constructors/602737/2 "2022-07-12T06:43:54Z")

</div>

By changing the implementation as follows, the generated blueprint class is not null anymore, and the asset is loaded

```nohighlight
void UMetahumanUtil::SpawnMetahuman(AActor* CurrMH)
{
    UE_LOG(LogTemp, Warning, TEXT("Spawning metahuman"));
   
    UWorld* World = CurrMH->GetWorld();

    FActorSpawnParameters SpawnParams;
    SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;

    FVector Loc(-60, -10, 40);
    FRotator Rot(0, 0, 90);
    
    TSoftClassPtr<AActor> MetahumanClass = TSoftClassPtr<AActor>(FSoftObjectPath(TEXT("/Game/Metahumans/Aoi/BP_Aoi.BP_Aoi_C")));
    UClass* AssetClass = MetahumanClass.LoadSynchronous();
    
    UE_LOG(LogTemp, Warning, TEXT("AssetClass name is %s"), *AssetClass->GetName());
    
    World->SpawnActor<AActor>(AssetClass, Loc, Rot, SpawnParams);

    
    UE_LOG(LogTemp, Warning, TEXT("Spawned metahuman"));
    
}

```
