Binding APlayerController with Character Class

Hi,
I’m new to UE4 and I’m trying to make a first person shooter game where I can switch(spawn) into different characters.
Let’s say I have 10 different characters, but they share basic movement key bindings such as ‘w’ ‘a’ ‘s’ ‘d’ movements and mouse xy movements and ‘space bar’ as jump.
For every different character, I do not want to write the same code again and again, so I figured I can write basic movement codes in PlayerController class and write each unique abilities in their Character class.
I’m not sure if this is even the right way to use PlayerController class, but here are my codes (from UE fps tutorial).

This is my AllPlayerController.h

UCLASS()
class OVERWATCH_API AAllPlayerController : public APlayerController
{
	GENERATED_BODY()
	//called to bind functionality to input
	virtual void SetupInputComponent() override;
	
	//Handles input for moving forward and backward
	UFUNCTION()
	void MoveForward(float Value);

	//Handles input for moving right and left
	UFUNCTION()
	void MoveRight(float Value);

	// Sets jump flag when key is pressed.
	UFUNCTION()
	void StartJump();

	// Clears jump flag when key is released.
	UFUNCTION()
	void StopJump();

	//Handles input for mouse X
	UFUNCTION()
	void YawInput(float Value);

	//Handles input for mouse Y
	UFUNCTION()
	void PitchInput(float Value);

};

This is my AllPlayerController.cpp

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

	// Set up "movement" bindings
	InputComponent->BindAxis("MoveForward", this, &AAllPlayerController::MoveForward);
	InputComponent->BindAxis("MoveRight", this, &AAllPlayerController::MoveRight);

	// Set up "look" bindings
	InputComponent->BindAxis("Turn", this, &AAllPlayerController::YawInput);
	InputComponent->BindAxis("LookUp", this, &AAllPlayerController::PitchInput);

	// Set up "action" binding
	InputComponent->BindAction("Jump", IE_Pressed, this, &AAllPlayerController::StartJump);
	InputComponent->BindAction("Jump", IE_Released, this, &AAllPlayerController::StopJump);
}

void AAllPlayerController::MoveForward(float Value)
{
	//Find out which way is "forward" and record that the player wants to move that way
	FVector Direction = FRotationMatrix(GetCharacter()->Controller->GetControlRotation()).GetScaledAxis(EAxis::X);
	GetCharacter()->AddMovementInput(Direction, Value);
}

void AAllPlayerController::MoveRight(float Value)
{
	//Find out which way is "right" and record that the player wants to move that way
	FVector Direction = FRotationMatrix(GetCharacter()->Controller->GetControlRotation()).GetScaledAxis(EAxis::Y);
	GetCharacter()->AddMovementInput(Direction, Value);
}

void AAllPlayerController::StartJump()
{
	GetCharacter()->bPressedJump = true;
}

void AAllPlayerController::StopJump()
{
	GetCharacter()->bPressedJump = false;
}

void AAllPlayerController::YawInput(float Value)
{
	GetCharacter()->AddControllerYawInput(Value * GetWorld()->GetDeltaSeconds());
}

void AAllPlayerController::PitchInput(float Value)
{
	GetCharacter()->AddControllerPitchInput(Value * GetWorld()->GetDeltaSeconds());
}

I would like to use above basic movements for all my characters and bind special abilities such as keyboard input ‘e’ to each character class.

Thank you.

Setting up ALL your bindings in the Controller is not a viable route because binding an action requires an instance of the target class which will be unknown at runtime. There are two general approaches I can think of:

  • Put all common bindings in the Controller, and specific bindings in the Character classes (I don’t like this much as it breaks encapsulation)
  • Use proper inheritance in your Character classes, where you start with a base class that contains all the common action bindings and implementations, and from that derive new classes where you add the new/specific action bindings implementations. You will also be able to override previously defined implementations if required.

I’d go for the second option.

Thank you for your answer.
I forgot that I could use inheritance.
Thank you.