Action Mappings – one button responses for an FPS character

An Action mapping is for handling single-button pushes (not buttons that are held down). For buttons that should be held down, be sure to use an Axis mapping instead.

Getting ready

Have a UE4 project ready with the actions that you need to complete, such as Jump or ShootGun.

How to do it...

  1. Open Settings | Project Settings | Input.
  2. Go to the Action Mappings heading, and click on the + icon beside it.
    1. Start to type in the actions that should be mapped to button pushes. For example, type in Jump for the first Action.
    2. Select a key to press for that action to occur, for example, Space Bar.
    3. If you would like the same action triggered by another key push, click on the + beside your Action Mappings name, and select another key to trigger the Action.
    4. If you want that the Shift, Ctrl, Alt, or Cmd keys should be held down for the Action to occur, be sure to indicate that in the checkboxes to the right of the key selection box.
    How to do it...
  3. To link your Action to a C++ code function, you need to override the SetupPlayerInputComponent(UInputControl* control ) function. Enter the following code inside that function:
    voidAWarrior::SetupPlayerInputComponent(UInputComponent* Input)
    {
      check(Input );
      // Connect the Jump action to the C++ Jump function
      Input->BindAction("Jump", IE_Pressed, this, &AWarrior::Jump );
    }

How it works…

Action Mappings are single-button-push events that fire off C++ code to run in response to them. You can define any number of actions that you wish in the UE4 Editor, but be sure to tie up Action Mappings to actual key pushes in C++.

See also

  • You can list the Actions that you want mapped from C++ code. See the following recipe on Adding Axis and Action Mappings from C++ for this.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.196.175