Waw_K
(Waw_K)
August 14, 2015, 9:00pm
1
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 );
}
joeGraf
(joeGraf)
August 14, 2015, 9:22pm
2
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
Waw_K
(Waw_K)
August 14, 2015, 9:52pm
3
Thank you once again joeGraf! I had to include MyCharacterPawn also but everything works great now. Thanks.