How your players can touch you (or player input)…

Handling user input in a customized way is usually one of the first things someone wants to do when attempting to create a UDK game from scratch. In the UDK, this involves working with your binding INI file and implementing a PlayerController class.

First, lets take a look at a binding file. In this case, I will show you a snippet of my customized UTInput.ini.

Bindings=(Name="GBA_StrafeRight",Command="Axis aStrafe Speed=+1.0")
Bindings=(Name="GBA_StrafeLeft",Command="Axis aStrafe Speed=-1.0")
Bindings=(Name="GBA_Backward",Command="Axis aBaseY Speed=-1.0")
Bindings=(Name="GBA_MoveForward",Command="Axis aBaseY Speed=1.0")

You’ll notice a few things. First, bindings are defined with a name and a command. The name can be the name of an actual input trigger (a keyboard key, a mouse click, an XBox button, etc), or it can be an arbitrary name, creating a binding meant to be used by other bindings. In the snippet I gave above, GBA_MoveForward is one such binding. These bindings are useful when you are developing for consoles and PC at the same time, something we mostly won’t do with the UDK (for now).

Bindings also require a command. That command can be a reference to another binding, such as how GBA_MoveForward is the command for the ‘W’ key, or it can be a function in your PlayerController class. This is how the PlayerController and user input are linked together.

In my custom UTInput.ini, you’ll notice I have bound the LeftMouseButton trigger to the Select command, and the RightMouseButton trigger to the Interact command. In the PlayerController example below, you will notice I have two functions: one named Select and one named Interact. These are the functions that the Unreal engine will invoke in response to my bindings.

class RpgToolkitPlayerController extends PlayerController;

var transient Actor SelectedActor;
var transient Camera Camera;

exec function Select() {
	`log("Select called");

exec function Interact() {
	`log("Interact called");

	SelectedActor = none;

We mark the functions exec because bindings use the console to invoke their functionality. The console can only invoke functions which are marked with the exec modifier. A nice side effect of this is that we can also call the functions from the console.

There is one other feature that command binding offers which can be very useful: OnRelease triggers. Instead of a calling a single function when the control trigger is released, you can instruct Unreal to call one function when the button is pressed, and another function when the button is released. Setting up this kind of binding in your input configuration is shown in the following example taken from the default UDK configuration:

Bindings=(Name="GBA_Fire",Command="StartFire | OnRelease StopFire")

In this example, Unreal will call the StartFire function when the left mouse button is pressed. It will then call the StopFire function when the left mouse button is released.

One other thing to note about binding user input to PlayerControllers this way: It’s state safe. You can override your input functions in your state blocks to create different input functionality based on your game state. This comes in very hand for handling things like pause menus or inventory screens.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: