How are pawns controlled?

Control Logic In Pawn

In all kind of approaches, as far as I know, it is clear that the control logic of the Pawn must be implemented on Pawn.


void AMyPawn::SetThrottle(float Axis)
{
    // Control logic goes here
    AddActorWorldOffset(GetActorForwardVector() * MyPawnVelocity * Axis * DeltaTime);
}

Player Input Binding in Pawn

Pawn has a setup function for Player called SetupPlayerInputComponent. This function recieves Player Input by binding PlayerController’s InputComponent’s methods then you must connnect your Pawn’s control logic by using these Axis and Action mappings.


void AMyPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
    Super::SetupPlayerInputComponent(InputComponent);
    InputComponent->BindAxis("Throttle", this, &AMyPawn::SetThrottle);
}

Player Input Binding in PlayerController

However, there is an other aproach for this by not implementing SetupPlayerInputComponent method on the Pawn which you mentioned I assumed. You can always bind Input from PlayerController.


void AMyPlayerController::SetupInputComponent()
{
	Super::SetupInputComponent();

	InputComponent->BindAxis("Throttle", this, &AMyPlayerController::SetThrottle);
}

void AMyPlayerController::SetThrottle(float Axis)
{
    auto MyPawn = Cast<AMyPawn>(this->GetPawn());
    if (MyPawn) 
    {
        MyPawn->SetThrottle(Axis);
    }
}

The main idea here is the Pawn has a function to control it from outside either PlayerController or AIController.