Download

AddMovementInput works on a class that inherits from pawn, despite the documentation sayings that this shouldn't happen

This is a quick one. I can’t find a clear explanation elsewhere so I’ll post this here in hopes that someone can shed light on this. I’d prefer a resource to an explanation if possible. Give me homework.

I have written a simple class to help me understand what is happening. Here is relevant code from the header file, as well as the body of SetupPlayerInputComponent(…) and one of the move functions.

It may be relevant that my pawn class inherits from Pawn, not from BasePawn.


UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
		class USphereComponent* sphereComponent;

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
		class UFloatingPawnMovement* floatingMovement;

	// ------------ //
	// -- Inputs -- //
	// ------------ //

void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent);

UFUNCTION()
	void moveX(float axisValue);

UFUNCTION()
	void moveY(float axisValue);

void APlayerPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) 
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	InputComponent->BindAxis("MoveX", this, &APlayerPawn::moveX);
	InputComponent->BindAxis("MoveY", this, &APlayerPawn::moveY);
}

void APlayerPawn::moveX(float axisValue)
{
	AddMovementInput(FVector(axisValue, 0, 0), 1, false);
}

In the documentation for AddMovementInput(…), we are given the information “Base Pawn classes won’t automatically apply movement, it’s up to the user to do so in a Tick event”. Yet, the way I have set things up, my pawn will response appropriately to input.

Is the documentation outdated, or am I not understanding what is happening in the backend?

The pawn class doesn’t apply your movement input but the UFloatingPawnMovement component that you have added to your pawn does.