How to spawn a custom blueprint pawn from c++

Hi Guss42,

Here is how I spawn a blueprint pawn class from C++.

Inside the constructor, I load the blueprint pawn class :

static ConstructorHelpers::FObjectFinder<UClass> PawnObject(TEXT("Class'/Game/Characters/Blueprints/BP_Pawn.BP_Pawn_C'"));
PawnClass = PawnObject.Object; // TSubclassOf<class APAwn> PawnClass; is declared in my class' header.

Note that the reference of the resource has to end with a “_C”.

Now inside the function executed server-side that spawns the pawn, I do as follows :

FActorSpawnParameters SpawnInfo;
APawn * pawn = GetWorld()->SpawnActor<APawn>(PawnClass, playerStart->GetActorLocation(), playerStart->GetActorRotation(), SpawnInfo);

Hope it helps!

Cheers.