How to handle input from PlayerController instead of Pawn

Just BTW, the code should execute faster when done like this (only 1 cast operation instead of potentially 3)

const APlayerCharacter* ControlledCharacter = Cast<APlayerCharacter>(GetControlledPawn());

if (ControlledCharacter)
     {
         InputComponent->BindAxis("Walk", ControlledCharacter, &APlayerCharacter::Walk);
         InputComponent->BindAxis("Strafe", ControlledCharacter, &APlayerCharacter::Strafe);
     }
     else
     {
         GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "Cast<APlayerCharacter>(GetControlledPawn()) is NULL");
     }
1 Like