Function 'Add Mapping Context' - Proper Usage

Hello Forum,

I have a class (Blueprint) with the name PLAYER, and the parent class is ‘Default Pawn’. In its event ‘BeginPlay’, I enable enhanced input with the function ‘Add Mapping Context’. The class has a camera and user input is used to move. This works fine.

I have another class (Blueprint) with the name CONTROLER, and the parent class is ‘PlayerController’. In this class I DON’T enable enhanced input.

PLAYER is the default pawn class (in project settings).
CONTROLLER is player controller class (in project settings).

I tried using an enhanced input action in the CONTROLLER class, and it works. Does this mean that you only have to call ‘Add Mapping Context’ once in a blueprint, and it works in all other blueprints?

Next step, I removed ‘Add Mapping Context’ from PLAYER, and added it to the event ‘BeginPlay’ from CONTROLLER. Everything still worked.
I got the code from tutorials, but doesn’t it make more sense to put ‘Add Mapping Context’ in the CONTROLLER class? Or am I missing something?

Thanks,

Semantics would point to Controller class, while all the input events are in the character class. Honestly it doesn’t matter if its in the character or controller. Yet, the controller is persistent. YOu will always have one, not the case for Pawn.

I personally have mine in the controller. I have functions that Load/Unload it and which IMC to use based on the Pawn class (character, vehicle, other etc).

Just so you know…
When an input is pressed the Controller is first checked for the event, then Level BP, then Pawn.

If the event Consumes Input the check flow will stop.

For example say we have Space Bar as an input in all three class that prints a string. On input press each would execute their events print string down the line. Controller, Level BP, then Pawn.

If you then set the Level BP event to consume input. Then Controller and Level BP would print, but not the Pawn.

Great, thanks.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.