I’ve been searching for answers, but most of them are either outdated (eg. does not use the Enhanced Input system) or suggest a solution that I cannot agree with.
So my main goal is to separate the controllable pawns and the control logic (i.e. input handling). This is done by mapping input actions to functions in the player controller (and adding input mapping contexts accordingly).
This works fine until there are a small number of controllable pawns. Currently, the player’s movement (move left-right and jump, atm) is listened by the controller and the controlled pawn’s functions are called directly.
However, this solution is not scalable. What happens when I’d like to introduce a new object in the world that can be controlled but with a completely different scheme? Of course I can:
- Create new input actions
- Add them to the player controller
- Register input action handlers in the controller
- Bound appropriate input mapping context in the
OnPossess
function - Call methods directly on the downcasted possessed pawn
There are multiple problems with this solution:
- Need to branch in the
OnPossess
function to determine which input mapping contexts should be added and/or removed - Need to contain all possible input actions and their handlers (can be a good thing tho)
- Need to downcast for the specific type of the possessed pawn if there is a special logic that must be executed when the given input is handled
Is there any appropriate and modern way to do input handling in the controlled while keeping it scalable, so it’s not a pain to introduce a new controllable pawn?
Somewhat related posts:
- Player Controller with Enhanced Input System
- How to handle complex user input?
- How to handle input from PlayerController instead of Pawn - #13 by Shmoopy1701
- https://www.reddit.com/r/unrealengine/comments/163a7bm/player_controller_vs_pawn_class_for_handling/
- https://www.reddit.com/r/unrealengine/comments/pa3ztu/how_should_i_get_a_controller_to_control/