How to cast from MyCharcaterPawn to Pawn

Hi!
I want to cast MyPawnCharacter to Pawn. I’m tyring to use Posses() function to take control on another Pawn, but Posses() needs Pawn variable. I have problem with syntax. Any help?

It’s something like this

void MyPlayerController::ChangePlayer()
{
	MyGameMode* GM = (MyGameMode*)GetWorld()->GetAuthGameMode();

	AMyCharacter* PawnFromWorld = GM->SpawnedPawn;
	APawn* PawnToPosses = Cast<APawn>(PawnFromWorld);//////// <---???????
	Possess(PawnToPosses );
}

Your game mode code has potential problems. You should use:

MyGameMode* GM = Cast<MyGameMode>(GetWorld()->GetAuthGameMode());

or

MyGameMode* GM = GetWorld()->GetAuthGameMode<MyGameMode>();

and then

Possess(GM->SpawnedPawn);

You don’t need an explicit cast for the SpawnedPawn because the compiler knows they are the right type due to Character inheriting from Pawn

Thank you once again joeGraf! I had to include MyCharacterPawn also but everything works great now. Thanks.