Download

Cast to ULocal Player failed

I try to get local player but always get null pointer:


void AMyBasePlayerController::GetPersistentUser()
{

ULocalPlayer* localPlayer = GetWorld()->GetFirstLocalPlayerFromController();

UMyLocalPlayer* RoPlayer = Cast<UMyLocalPlayer>(localPlayer);

}

RoPlayer always is null!

The reason would be that the cast fails, so you’re not using your custom Local Player class.

Go to Project Settings -> Engine (General Settings) -> Local Player Class and switch it to your custom class. From then on it should work.

Thanks. Solved.