Skip to main content

Input/Controller

How input and controller work in this template.

InputListener

I made a component that selects which input it takes from some configuration.

The Global InputListenerComponent contains several InputListener objects, and the active one depends on the currently controlled pawn.

Diagram

For example, in this template, we have two control possibilities: the hero character and the flying bird.

Diagram

If you look at the configuration in BP_SFR_Hero_Controller on the BP_SFR_InputListenerComponent, you’ll notice that I associate the InputListener with a Tag:

Diagram

The code that activates the input listeners can be inspected in the Client_OnPossessPawn function in the BP_SFR_Hero_Controller. This is what happens at the end, after replication:

Diagram

To know where the source call comes from (before it communicates with the server to be replicated, on the client side), you can check the OnMountStateChange in the PlayerController. You'll see that I add a condition to check if I possess a pawn that can be mounted, or else I'm supposed to control the Hero.

Diagram

How each input event work

In an effort to keep dependencies as low as possible, so you can manage input events with your own Enhanced Input, I notify input events in the InputListener using Tags as well.

For example, for the jump key, I notify in my InputListenerComponent that the tag SFR.Action.Jump is activated when the key is pressed and deactivated when it is released:

Diagram

This is how we differentiate actions based on which pawn we are controlling. You can look, for example, in the HeroInputListener to see what happens when it’s Jump, and similarly in the FlyBirdInputListener.

Example in HeroInputListener:

Diagram

Note that you will notice that the majority of actions issued on the controlled fly bird character are redirected to RequestDoActionTag because, depending on the context, I want to replicate the action request for it to work in multiplayer.

Diagram

Diagram