How to use a player controller to control a pawn?


Currently I am using default player controllers. I posses every controller to a pawn, it’s working. The problem is that the first controller is always controlling keyboard and gamepad. I want to change that by creating my own controller class that inherits from PlayerController.

But how does that binding between Pawn and PlayerController works in detail? Like what happens in detail if a keyboard key was pressed? And why is only the pawn with Controller0 is getting keyboard input?
I assumed that the controller had a reference to the possessed pawn, but in the blueprints I cannot find anything like “GetPossessedPawn” or something…

For a possible solution I was thinking about following idea (see image). The controller (must be the first controller) is getting Keyboard/Gamepad0 input. If the input is from the keyboard, the command gets delegated to the “keyboard” pawn. If its not from the keyboard, the possessed pawn is getting that command.
This idea has some problems:

  1. There is no “GetPossessedPawn” function.
  2. This must be done for every InputAction. No generic way… :frowning:
  3. The difference between Pressed and Released must be handled

Any idea for a solution without the 3 problems?

Check your default project settings:

and game mode settings:

You can set the pawn and controller types in there.

You may misunderstood me. I am using the Inputs from the project settings and I am using my own GameMode where I set my Pawn and Controller. But how can I control my pawn in my controller? I updated my question, maybe it’s clearer now?

Sorry, not sure what you mean by “how can I control my pawn in my controller”. Are you just trying to access the pawn your controller is currently assigned to?

Yes, exactly. That is one of my problems. I tried to make my question clearer again, now with image.

Player 1 will always be set to Controller0. Other players that join locally will be set to Controller1, Controller2, etc. As far as getting the pawn that will be controlled, you can use “Get Controlled Pawn” and send inputs to that actor.

One note PlayerControllers don’t have index, the “Get Controlled Pawn” get controller based of order index which may change