UE Cast question

Why in the TankPlayerController.cpp the UE Cast function reported below:

ATank* ATankPlayerController::GetControlledTank() const
{
return Cast< ATank >(GetPawn());
}

convert the APawn* pointer returned by GetPawn() into an ATank object?
Shouldn’t the cast match the type returned by GetControlledTank() function (so an ATank* pointer)?
I expected:

return Cast< ATank* >(GetPawn());

Thanks in advance,
regards,
D.

Because the Cast function returns a pointer. So if you put Cast<ATank*> that would mean a ATank** would be returned. It returning a pointer also allows the cast to return nullptr for a failed cast.

Privacy & Terms