How do I set up input inside the PlayerController instead of the character?

I want to handle input inside a custom player controller class instead of my character’s class. Do I have to cast? If yes the how? I tried searching everywhere but for some reason nothing helped.

You should be able to use the SetupInputComponent() function inside of the PlayerController class – or YourPlayerController class, inherited from PlayerController.

If you look at the function, it creates a InputComponent that you can then use to bind input to.

There may be more to this step, such as making sure that the controller is the one accepting input, instead of the the Character. I am not 100% but I would start by looking at the player controller function and see if you can use it in a way you want.

Inside your CustomCharacterController.h file, you need something like this:

virtual void SetupInputComponent() override;

Then, in your cpp file:

void ACustomCharacterController::SetupInputComponent()

	InputComponent->BindAction("MyAction", IE_Pressed, this, &ACustomCharacterController::FunctionToCall);

Then, just make sure the game’s spawning your custom character controller for the player and not the default controller. That’s usually set in the GameMode you’re running.

1 Like

Raap ! You saved my time and my life ! Thank you :smiley: