In this post we’re going to create various Action Bindings with parameters. Moreover, we’re going to see a way to change the content of our parameters on run time!

This post assumes you’re familiar with UE4 Delegates. In case you don’t quite remember, or know, what or how to use them, I’ve got you covered!

Creating our Inputs

Create any C++ project template and add the following action mappings:


Then, open up the header file of your character and add the following functions:

Then, inside your character’s source file add the following implementation for the OneParamFunction and the TwoParamsFunction:

Before we go any further let’s take a step back to explain how inputs work in C++ inside UE4.

Your character contains a component named, InputComponent (at least this is happening on the template project !) which is responsible for checking if a valid device for inputs (such as a gamepad / keyboard / mouse etc..) exists. Moreover, that component contains all the available inputs for the specific character.

Currently, there are two types of bindings in UE:

  • Axis bindings
  • Action bindings

The main difference is that axis bindings execute in each frame, whereas action bindings execute when certain conditions are met (for example the user double clicks, or presses a button).

In this post we’re going to focus solely on action bindings.

In order to declare an action binding you need to:

  • Associate the action mapping we’ve specified using the Editor with an input event (ie a button press)
  • Declare which function will fire when the input event occurs

Inside the First Person C++ Project template you can locate the following line of code inside the SetupPlayerInputComponent:

This is the standard way to add an action binding. In this post, we will explore a different way of adding an action binding.

In reality, inside C++ an Action Binding is actually a struct which contains useful information, such as:

  • Action Delegate (I will explain in a bit what this is)
  • Action Name (which is the actual name of your binding – this must be associated with the action mapping that was specified in your Editor)
  • A Key event (which describes the input type. In our case we’re going to use the IE_Pressed key event which describes a button tap)

The Action Delegate is essentially a handler, which points to a function that will execute when we have a valid input based on the key event of our Action Bind. Having said all that, locate the SetupPlayerInputComponent function and add the following code after the default inputs:

The remaining steps are to implement the function ChangeParameters and specify some initial values for our exposed properties through the Editor.

Changing our variables on run time

The ChangeParameters function will generate two random values and will re-bind the TwoParamsInput Action Binding. Having said that, here is the implementation:

Save and compile your code. Then, switch to your Editor and:

  • Assign values to our variables from within the character Blueprint
  • Test your code

Here is a screenshot of my default values:


And here is a screenshot of my end result (after calling the change parameters function a couple of times):




Share postShare on Facebook19Tweet about this on TwitterShare on LinkedIn0Share on Reddit0