Setting Up Inputs

A How To Guide for Setting Up Inputs in Unreal Engine 4.

Choose your operating system:

Windows

macOS

Linux

After you have imported or created your Character, Vehicle, or Flying Spaceship Asset, you will need to define how it reacts to Player Input. Defining Input is primarily done through user defined Bindings of Action Mappings (which are for key presses and releases) and Axis Mappings (which are for inputs that have a continuous range).

Once you have defined your Mappings, you can then bind them to behaviors in Blueprints or C++.

Implementation Guide

In this guide, you will create a simple character and set it up to receive input, you will then assign the character to a GameMode so that it is the default pawn during gameplay. If you are familiar with setting up a character or have a character that you want to provide input to (and have a GameMode set up to use your character), you can skip the creating a character section and jump right into creating new inputs and implementing them.

Creating a Simple Character

In this section, we will create a character that we can assign input to (if you already have a Character Blueprint , you can skip this step).

For this example, we are using the Blank project template with Starter Content included.

  1. Inside your project, under Shapes , Right-click on the Shape_NarrowCapsule shape and select Asset Actions - Create Blueprint Using .

    Input2_1.png

    This will be our simple character that we will control.

  2. Inside the Blueprints folder, open the newly created Blueprint, then click File and Reparent Blueprint option.

    Input_2.png

    We need to change the Class of the Blueprint from an Actor to a Character .

  3. In the pop-up window that appears, select the Character option.

  4. In the upper right of the Blueprint Window, click the Components tab.

  5. On the Components tab under the Components window, click Add Component and add a Spring Arm .

    Input2_3.png

    The Spring Arm component tries to maintain its children at a fixed distance from the parent, but will retract the children if there is a collision, and will spring back when there is no collision. The children in this case will be a Camera so that we have a third person perspective.

  6. With the Spring Arm selected, under Details , search for rotation .

  7. Under Camera Settings , check the Use Pawn Controller Rotation box.

    Input2_4.png

  8. Click the Add Component button again and add a Camera , then drag and drop it onto the Spring Arm component.

    Input2_5.jpg

    This will make it a child of the Spring Arm .

  9. With the Camera selected, set the Location and Rotation values under Transform to 0 .

    Input_7.png

  10. Select the StaticMesh1 component, then under Details , set the Z value for Location to -90.0 .

    Input_6.png

  11. Compile and Save then close the Blueprint.

Creating a Game Mode to use the Simple Character

Now that we have created a simple character, we need to create a GameMode and tell it to use our new character.

  1. From the Content Browser , click the New Button, then click the Blueprint option.

  2. In the pop-up window that appears, click the Game Mode Button.

    Input_8.png

  3. Give it a name, then open the GameMode Blueprint and click the Defaults tab.

  4. On the Defaults tab, under the Classes section, click the Default Pawn Class drop-down and select the new character.

    Input2_9.png

  5. Compile and Save then close the Blueprint.

  6. From the Main Editor window, click the Edit Button from the menu bar and select Project Settings .

    Input2_10.png

    We are now going to tell our project to use the newly created GameMode .

  7. In Project Settings , click the Maps & Modes option.

  8. Under Maps & Modes , for Default Modes , click the Default GameMode drop-down and select your GameMode .

    Input2_11.png

Creating New Inputs (Action/Axis Mappings)

The steps below will guide you through adding new Action and Axis Mappings to your project which can then be assigned to your character.

  1. In the Project Settings menu, under Engine , click the Input option.

  2. Under Bindings , click the + signs next to Action Mappings and Axis Mappings to recreate the setup below.

    Input_12.png

  3. Fill in the empty mappings as seen below.

    Input2_13.png

    Here you are naming each of the mappings and assigning an Input for that mapping. Make sure to set the Scale values to -1.0 where highlighted as the Scale acts as a multiplier on the value of the key when summing up the Axis' value (which allows us to get the opposite direction).

Implementing Action/Axis Mappings in Blueprints

Once you have created Inputs via Project Settings , you can then call those Inputs from within a Blueprint . In this section, we will implement those Input settings for the simple character (or your character if you are using your own).

  1. Inside your project, open the Character Blueprint ( Shape_NarrowCapsule ) you want to assign Input to.

  2. Inside the Blueprint, Right-click anywhere in the graph and search for Turn then add the Turn Axis Event.

    Input2_14.png

  3. Drag off the Axis Value and search for Yaw , then add the Add Controller Yaw Input node.

    Input_15.png

  4. Right-click in the graph and add the LookUp Axis Event.

  5. Drag off the Axis Value and search for Pitch , then add the Add Controller Pitch Input node.

    Input_16.png

  6. Right-click in the graph and add the Jump Axis Event.

  7. Drag off the Pressed pin and search for Jump function.

    Input2_17.png

  8. Right-click in the graph and add the MoveForward Axis Event.

    Input2_18.png

  9. Drag off the Axis Value and add the Add Movement Input node.

  10. Right-click in the graph and add the MoveRight Axis Event.

  11. Drag off the Axis Value and add the Add Movement Input node.

    Input2_19.png

    The events have been added, however we need to specify direction for each still.

  12. Right-click in the graph and search for Get Control Rotation .

    Input2_20.png

  13. Drag off the Return Value and add a Break Rot node (to break the rotation into Pitch, Yaw, and Roll).

  14. Drag off the Yaw pin and add a Make Rot node (to make a rotation out of Pitch, Yaw, and Roll).

    Input2_21.png

  15. Right-click on the Make Rot node and select Break link to Break Rot (Yaw) .

    Input2_22.png

    We want to zero out the Pitch and Roll and only keep the Yaw .

  16. Connect the Yaw of the Break Rot to the Yaw of the Make Rot .

  17. Drag off the Return Value of the Make Rot and add a Get Forward Vector and Get Right Vector node.

  18. Connect the Get Forward Vector to the World Direction tied to MoveForward Event.

  19. Connect the Get Right Vector to the World Direction tied to the MoveRight Event.

    Input_23.png

    The sequence should look similar to above.

  20. Compile and Save , then close the Blueprint.

  21. Play in the editor.

You should now be able to move around in the scene and jump with the capsule character we created (or the character you elected to use).

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss