How can i Setup Enhanced Input Mapping in PlayerController Class?

I Want to Setup my input mapping in PlayerController Class for my game. So that when i am playing the game, gameplay mapping is enabled and when i press escape, UI mapping will be used. but can’t set this up because the following function does not inherit from the player controller class, is the something that i am doing wrong or is there a better way to do it. please let me know.

SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)

Below is my PlayerController.h code -

class UInputMappingContext;
class UInputAction;

UCLASS()
class BALLGAME_API ABallPlayerController : public APlayerController
{
GENERATED_BODY()

public:

ABallPlayerController();
virtual void Tick(float DeltaTime) override;
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

protected:
virtual void BeginPlay() override;

private:
UPROPERTY(EditAnywhere, Category = Inputs)
UInputMappingContext* InputMappingContext;

UPROPERTY(EditAnywhere, Category = Inputs)
UInputAction* IA_Move;

UFUNCTION(BlueprintCallable)
void Move(const FInputActionValue& Value);

};

SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) should be in your APawn, not your player controller.

1 Like

It’s perfectly reasonable and in some cases preferred to setup the input binding in the player controller, and then forward input to the pawn.

From the Unreal Docs:

if you have more complex needs, like multiple players on one game client, or the ability to change characters dynamically at runtime, it might be better to handle input in the PlayerController
Player Controllers in Unreal Engine | Unreal Engine 5.3 Documentation

Read this discussion here, it discusses your options for this.

1 Like

Nobody argued this.

OP is using SetupPlayerInputComponent, which only exists on the pawn. So I’ve let them know that this function is for the pawn.

The PlayerController uses SetupInputComponent, not SetupPlayerInputComponent, so if OP would prefer to set up their input component on the player controller, then they should use that instead.

1 Like