How to load blueprint .uasset and put it in the scene by c++

I want to load .uasset model and put it in the scene. However, its reference path is something like “Blueprint’/Game/model.model’”. I load it as UBlueprint object, but don’t know how to put the model in the scene.

I can load staticmesh .uasset and put it in the scene successfully, but don’t what to do the blueprint model .uasset file.
Any help here?

Let’s say the blueprint’s path is /Game/Blueprints/MyBPActor.

Here is the code needed to spawn the blueprint Actor in the level:

In your object’s header file:

UPROPERTY(VisibleAnywhere)
TSubclassOf<AActor> MyBPActorClass;

This stores the “Blueprint Generated Class” of the Blueprint as a UClass object.

In the CPP file, in the object’s constructor

static ConstructorHelpers::FClassFinder<AActor> MyBPActorClassFinder(TEXT("/Game/Blueprints/MyBPActor"));
MyBPActorClass = MyBPActorClassFinder.Class;

This takes the Blueprint and turns it into the UClass object

In the CPP file, when you want to spawn the actor:

AActor* MyBPActor = GetWorld()->SpawnActor<AActor>(MyBPActorClass);

You’ll also need to include this:

#include "UObject/ConstructorHelpers.h"

So, with this method, don’t think of the blueprint as an asset, think of it more as a class.

Hope it helps!

1 Like