Hi!
I’m looking for a way in c++ to posses my default pawn without setting “Posses” in the Blueprint
This is what I’ve tried to far:
In GameMode I’m not able to get APawn* from the DefaultBPClass.
APlaygroundGameMode::APlaygroundGameMode()
{
// set default pawn class to our Blueprinted character
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/ThirdPerson/Blueprints/BP_MainPlayer"));
if (PlayerPawnBPClass.Class != NULL)
{
DefaultPawnClass = PlayerPawnBPClass.Class;
APlayerController* firstPlayer = UGameplayStatics::GetPlayerController(GetWorld(), 0);
APawn* pawn = Cast<APawn>(DefaultPawnClass);
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Some debug message0!"));
if (pawn != NULL) { // IS ALWAYS NULL
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Some debug message!"));
firstPlayer->Possess(pawn);
}
}
}
Issue is: Pawn is always NULL when casting
Question:
How can I get the reference to my DefaultPawn which is set in GameMode and Posses this from C++ ?
Thanks
(Sure this has been asked, but I was not able to find the thread, pointing me to an existing thread would also be helpful)