Using blueprints it is possible to create Input events that are directly bound to keys and buttons. However there is a better way to mapping the Input in Blueprints.
For the game logic it is better to create new Input events that represent actions that make sense in the game. For example, instead of create an Input event for the left mouse button that will trigger a gun, it is better to create an event called "Fire" and map all keys and buttons that can trigger this event.
To do the Input mapping, access in the editor the menu "Edit-> Project Settings..." and in the Engine category select the Input option. The image below shows the Input mapping of a new project without templates. There is no "Action Mappings" and "Axis Mapping" created, but there is already a default setting for the "Axis Config".
The controls of type "Axis" vary within a range of values instead of being as simple buttons and keys. The movement of mouse and the analog sticks of a gamepad are examples of controls of type "Axis".
To see an example of "Action Mappings" and "Axis Mapping", create a new Blueprints project using the template "First Person". Access the Input option of the project and see two "Action Mappings" created with the names "Jump" and "Fire".
The movement in first person is represented in the "Axis Mapping":
The keys and buttons can also be used in the "Axis Mapping". In the above example we have the "MoveForward" that is mapped to the "W" key with scale "1.0" and also to the "S" key with scale "-1.0" that represents the reverse direction.
All "Action Mappings" and "Axis Mapping" are available as events in the Blueprint editor, as well as the functions that can be used to query the values of the mapped Axes:
An event of type "Action Mappings" is generated when the keys / buttons associated with it are pressed or released. An event of type "Axis Mapping" reports the current value of the axis. The image below shows the difference:
The "Pawn" class has some functions related to movement and rotation. The "Character" class is an extension of "Pawn" class on Unreal Engine 4, so these functions can also be used in "Character" class:
The words Yaw, Pitch and Roll represents the rotation around each of the three axes of an Actor.
The script below shows how the movement of the player is done for front/back and for right/left.
The control of the player's view using the Mouse is shown in this image:
Next: Save and Load in Blueprints
Prev: Flow Control in Blueprints
Table of Contents