In this tutorial, you will create a Character and set it up to receive input, then assign the character to a GameMode so that it is the default pawn during gameplay. After you create your Character, you will define how it reacts to Player Input.
Unreal provides for more complex Input mappings for a variety of project types. Refer to Enhanced Input for additional documentation.
Project Setup
-
Create a new Games > Blank > Blueprint project named "SettingUpInput".
-
From the Editor, navigate to Edit > Project Settings > Input > Bindings.
-
Create a new Games > Blank > C++ project named "SettingUpInput".
-
In the Editor, navigate to Edit > Project Settings > Input > Bindings.

Action and Axis Mapping Setup
Defining Input is done through user-defined Bindings of Action and Axis Mappings. Both mappings provide a mechanism to conveniently map keys and axes to input behaviors by inserting a layer of indirection between the input behavior and the keys that invoke it.
Action Mappings are for key presses and releases, while Axis Mappings allow for inputs that have a continuous range. Once you have defined your Mappings, you can then bind them to behaviors in Blueprints or C++.
-
Click Add(+) next to Action Mappings to create a new Action named Jump.
-
From either the drop down arrow(1) or the Select Key Value button(2), search for and select the Space Bar key value.
-
Navigate to the Axis mappings and click Add(+) to create the following Axis Mapping names, Key values, and Scale values:
Axis Mapping Name Key Value Scale Value MoveForward W 1.0 S -1.0 MoveRight A -1.0 D 1.0 Turn Mouse X 1.0 LookUp Mouse Y -1.0
Creating the Example Character
Creating the Example Character
A Character is a special type of Pawn that has the ability to walk around. Characters extend from the Pawn class, and inherit similar properties such as physical representation of a player or AI entity within the world.
Refer to the Pawn and Input pages for additional documentation.
-
From the Content Drawer, Click Add(+), then from the Pick Parent Class menu choose Character as your parent class.
-
Name your Blueprint BP_ExampleCharacter, and double-click it to open its class defaults.
A Character is a special type of Pawn that has the ability to walk around. Characters extend from the Pawn class, and inherit similar properties such as physical representation of a player or AI entity within the world.
Refer to the Pawn and Input pages for additional documentation.
-
From the Content Drawer, navigate to the C++ classes folder, right-click and select New C++ Class, then choose Character as your parent class.
-
Name your character class "ExampleCharacter", then click Create Class.
Creating the SpringArm and Camera Components
Creating the SpringArm and Camera Components
When the Camera and SpringArm Components are used together, they provide functionality for a third-person perspective that can dynamically adjust to your game world. The camera component contains a camera that represents the player's point of view or how the player sees the world. The SpringArm component is used as a "camera boom" to keep the camera for a player from colliding into the world.
-
In the Components tab, click Add(+), then from the drop down search for and select Spring Arm. Rename your Spring Arm component CameraBoom.
-
Repeat step 1, but search for and select the Camera. Rename your Camera component FollowCamera.
-
From the Components tab, drag your FollowCamera onto the CameraBoom to attach it.
-
Select the CameraBoom in the Components tab, then navigate to the Details > Camera Settings and click the checkbox to enable the Use Pawn Control Rotation variable. When enabled, the Camera parent uses the view / control rotation of the pawn (ExampleCharacter).
For additional Spring arm and Camera settings that you could use for your Character's perspective. Refer to the Using Cameras documentation
-
Compile and Save.
When the Camera and SpringArm Components are used together, they provide functionality for a third-person perspective that can dynamically adjust to your game world. The camera component contains a camera that represents the player's point of view or how the player sees the world. The SpringArm component is used as a "camera boom" to keep the camera for a player from colliding into the world.
- In your code editor, navigate to ExampleCharacter.h. In the Class defaults, declare the following classes.
protected: UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Components") class USpringArmComponent* CameraBoom; UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Components") class UCameraComponent* FollowCamera; |
UProperty Specifiers are used to provide visibility of the component in the Blueprint Editor.
- Navigate to your
ExampleCharacter.cpp
file. Add the following libraries to the include line.#include "GameFramework/SpringArmComponent.h" #include "Camera/CameraComponent.h"
- Next, implement the following in the
AExampleCharacter
constructor.AExampleCharacter::AExampleCharacter() { //Initialize the Camera Boom CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom")); //Setup Camera Boom attachment to the Root component of the class CameraBoom->SetupAttachment(RootComponent); //Set the boolean to use the PawnControlRotation to true. CameraBoom->bUsePawnControlRotation = true; //Initialize the FollowCamera FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera")); //Set FollowCamera attachment to the Camera Boom FollowCamera->SetupAttachment(CameraBoom); }
The component calls the FObjectInitializer::CreateDefaultSubobjecttemplate, then uses the SetupAttachment method to attach to a parent Scene Component. When setting the Camera Boom to use the Pawn's control rotation, it uses its parent pawn's rotation instead of its own.
- Compile your code.
Setting the Character Mesh
-
In the Components panel, select the Mesh Skeletal Mesh Component.
-
Navigate to Details > Mesh > Skeletal Mesh and expand the drop-down menu. Select Browse Asset Options > Content > Show Engine Content.
-
Search for and select the TutorialTPP Skeletal Mesh.
-
Navigate to the Transform category, then set the Location and Rotation vector values to (0.0, 0.0, -90)
-
Compile and Save.
Creating the Action/Axis Functions to your Input Component
- In your
ExampleCharacter.h
class defaults, declare the following Input functions.protected: void MoveForward(float AxisValue); void MoveRight(float AxisValue);
- Navigate to your
ExampleCharacter.cpp
and implement yourMoveForward
andMoveRight
methods.void AExampleCharacter::MoveForward(float AxisValue) { if ((Controller != NULL) && (AxisValue != 0.0f)) { // find out which direction is forward const FRotator Rotation = Controller->GetControlRotation(); const FRotator YawRotation(0, Rotation.Yaw, 0); // get forward vector const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); AddMovementInput(Direction, AxisValue); } } void AExampleCharacter::MoveRight(float AxisValue) { if ((Controller != NULL) && (AxisValue != 0.0f)) { // find out which direction is right const FRotator Rotation = Controller->GetControlRotation(); const FRotator YawRotation(0, Rotation.Yaw, 0); // get right vector const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); // add movement in that direction AddMovementInput(Direction, AxisValue); } }
- Navigate to the SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) method, then implement the following code.
void AExampleCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump); PlayerInputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping); PlayerInputComponent->BindAxis("MoveForward", this, &AExampleCharacter::MoveForward); PlayerInputComponent->BindAxis("MoveRight", this, &AExampleCharacter::MoveRight); PlayerInputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput); PlayerInputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput); }
The Player Input Component links the AxisMappings and ActionMappings in your project to game actions. Both the Pawn and Character class contain methods that are inherited and can be used or extended for your custom characters. In our example, we've used the Pawn's AddControllerYawInput and AddControllerPitchInput functions, and the Character's Jump and StopJumping functions.
- Compile your code.
Creating the Action/Axis Functions to your Input Events
-
Navigate to My Blueprint > Functions, click Add(+) to add two new functions. MoveForward and MoveRight.
-
Select the MoveForward function, navigate to the Details > Inputs, then click Add(+) to add a new float value input named AxisValue.
-
Copy or Implement the logic below for the MoveForward function.
Begin Object Class=/Script/BlueprintGraph.K2Node_FunctionEntry Name="K2Node_FunctionEntry_0" ExtraFlags=201457664 FunctionReference=(MemberName="MoveForward") bIsEditable=True NodePosX=-32 NodePosY=16 NodeGuid=A0FF87524A53EDAA6CBEC48FEE0D9464 CustomProperties Pin (PinId=B427E05D444F66A59DA68E9A5D09AB7B,PinName="then",Direction="EGPD_Output",PinType.PinCategory="exec",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_CallFunction_7346 B27FCDDF43B9261BD870CE965B82DF38,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,) CustomProperties Pin (PinId=F01767A145595ED17A3E438A7F7BEFA2,PinName="AxisValue",Direction="EGPD_Output",PinType.PinCategory="real",PinType.PinSubCategory="double",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_CallFunction_7346 D95413A34BE985375A5C2F905CD8109F,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,) CustomProperties UserDefinedPin (PinName="AxisValue",PinType=(PinCategory="real",PinSubCategory="double"),DesiredPinDirection=EGPD_Output) End Object Begin Object Class=/Script/BlueprintGraph.K2Node_CallFunction Name="K2Node_CallFunction_7346" FunctionReference=(MemberName="AddMovementInput",bSelfContext=True) NodePosX=384 ErrorType=1 NodeGuid=CE1F697649E08F668E46BFA6FF6FE134 CustomProperties Pin (PinId=B27FC -
Select the MoveRight function, and add a new float value as instructed in step 2.
-
Copy or Implement the logic below for the MoveRight function.
Begin Object Class=/Script/BlueprintGraph.K2Node_FunctionEntry Name="K2Node_FunctionEntry_0" ExtraFlags=201457664 FunctionReference=(MemberName="MoveRight") bIsEditable=True NodePosX=64 NodePosY=-48 NodeGuid=5846746C4FEEF77A895638939B0C845C CustomProperties Pin (PinId=09949021438E59AA6E23A8B112C93B0D,PinName="then",Direction="EGPD_Output",PinType.PinCategory="exec",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_CallFunction_7346 B27FCDDF43B9261BD870CE965B82DF38,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,) CustomProperties Pin (PinId=0FE0FC0344DE295574151E8BA52B9628,PinName="AxisValue",Direction="EGPD_Output",PinType.PinCategory="real",PinType.PinSubCategory="double",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_CallFunction_7346 D95413A34BE985375A5C2F905CD8109F,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,) CustomProperties UserDefinedPin (PinName="AxisValue",PinType=(PinCategory="real",PinSubCategory="double"),DesiredPinDirection=EGPD_Output) End Object Begin Object Class=/Script/BlueprintGraph.K2Node_CallFunction Name="K2Node_CallFunction_7346" FunctionReference=(MemberName="AddMovementInput",bSelfContext=True) NodePosX=432 NodePosY=-64 ErrorType=1 NodeGuid=0A9F72574C55739F8ABF479B3DA34A3C CustomProperties Pin ( -
Navigate to the Event Graph. You need to set up your Axis and Action input events to call their respective functions. Copy or implement the logic below.
Begin Object Class=/Script/BlueprintGraph.K2Node_CallFunction Name="K2Node_CallFunction_0" FunctionReference=(MemberName="MoveForward",MemberGuid=C0341673464A891BBAB256A597CC129B,bSelfContext=True) NodePosX=752 NodePosY=96 NodeGuid=F58C25A840CC8F0AFBDAF29C9156738F CustomProperties Pin (PinId=0AB1925F4322FE3D3E6EB4A491889FC9,PinName="execute",PinToolTip="\nExec",PinType.PinCategory="exec",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,LinkedTo=(K2Node_InputAxisEvent_0 C6162D6E4C41B2636D72DB955E9701A2,),PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,) CustomProperties Pin (PinId=75B681B34A8D4B3145A6B88572E666E2,PinName="then",PinToolTip="\nExec",Direction="EGPD_Output",PinType.PinCategory="exec",PinType.PinSubCategory="",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUObjectWrapper=False,PinType.bSerializeAsSinglePrecisionFloat=False,PersistentGuid=00000000000000000000000000000000,bHidden=False,bNotConnectable=False,bDefaultValueIsReadOnly=False,bDefaultValueIsIgnored=False,bAdvancedView=False,bOrphanedPin=False,) CustomProperties Pin (PinId=A75F913B4741D285583415B3E8CFF56F,PinName="self",PinFriendlyName=NSLOCTEXT("K2Node", "Target", "Target"),PinToolTip="Target\nSelf Object Reference",PinType.PinCategory="object",PinType.PinSubCategory="self",PinType.PinSubCategoryObject=None,PinType.PinSubCategoryMemberReference=(),PinType.PinValueType=(),PinType.ContainerType=None,PinType.bIsReference=False,PinType.bIsConst=False,PinType.bIsWeakPointer=False,PinType.bIsUOb
Finished Code
ExampleCharacter.h
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "ExampleCharacter.generated.h"
UCLASS()
class SETTINGUPINPUT_API AExampleCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AExampleCharacter();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UPROPERTY(EditDefaultsOnly,BlueprintReadOnly)
class USpringArmComponent* CameraBoom;
UPROPERTY(EditDefaultsOnly,BlueprintReadOnly)
class UCameraComponent* FollowCamera;
void MoveForward();
void MoveRight();
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
ExampleCharacter.cpp
// Sets default values
AExampleCharacter::AExampleCharacter()
{
//Initialize the Camera Boom
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
//Setup its attachment to the Root component of the class
CameraBoom->SetupAttachment(RootComponent);
//Set the boolean to use the PawnControlRotation to true.
CameraBoom->bUsePawnControlRotation = true;
//Initialize the Camera Comp
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
//Set its attachment to the Camera Boom
FollowCamera->SetupAttachment(CameraBoom);
}
// Called when the game starts or when spawned
void AExampleCharacter::BeginPlay()
{
Super::BeginPlay();
}
void AExampleCharacter::MoveForward(float AxisValue)
{
if ((Controller != NULL) && (AxisValue != 0.0f))
{
// find out which direction is forward
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// get forward vector
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, AxisValue);
}
}
void AExampleCharacter::MoveRight(float AxisValue)
{
if ((Controller != NULL) && (AxisValue != 0.0f))
{
// find out which direction is right
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// get right vector
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
// add movement in that direction
AddMovementInput(Direction, AxisValue);
}
}
// Called every frame
void AExampleCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AExampleCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
// Set up gameplay key bindings
check(PlayerInputComponent);
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping);
PlayerInputComponent->BindAxis("Move Forward", this, &AExampleCharacter::MoveForward);
PlayerInputComponent->BindAxis("Move Right", this, &AExampleCharacter::MoveRight);
}
Creating the Character Blueprint
-
Navigate to your C++ Classes Folder and right click your ExampleCharacter, from the drop down menu select Create Blueprint class based on ExampleCharacter. Name your Blueprint BP_ExampleCharacter.
-
In the Components panel, select the Mesh Skeletal Mesh Component.
-
Navigate to Details > Mesh > Skeletal Mesh and expand the drop-down menu. In the Browser section, click the Settings Icon. Then from the context menu, select Content > Show Engine Content.
-
Search for and select the TutorialTPP Skeletal Mesh.
-
Navigate to the Transform category, then set the Location and Rotation vector values to (0.0, 0.0, -90)
Finished Blueprint
MoveForward

MoveRight

Event Graph

Creating the GameMode Blueprint
The GameMode defines the game's set of rules. These rules include what default pawn the player will spawn as when the game is launched. You need to set up these rules to spawn the Player Character you created.
-
In the Content Drawer, click Add(+) to create a new Blueprint Class, then from the drop down menu choose Game Mode Base as your Parent Class. Name your game mode "BP_InputGameMode".
-
In the Class defaults, navigate to Classes > Default Pawn Class, and select BP_ExampleCharacter.
-
Compile and Save.
-
Navigate to Edit > Project Settings > Maps and Modes. Set the Default GameMode to BP_InputGameMode.
-
Navigate to the Editor and select Play (Play in Editor)
You can now control your character's movement using the W, A, S, D keys. Moving the mouse moves the camera, and pressing the spacebar causes the character to jump.
The GameMode defines the game's set of rules. These rules include what default pawn the player will spawn when the game is launched. You need to set up these rules to spawn the Player Character you created.
-
In the Content Drawer, navigate to your C++ Classes folder, right-click the SettingUpInputGameModeBase, then in the drop-down menu select Create Blueprint Based on SettingUpInputGameModeBase. Name your game mode Blueprint "BP_InputGameMode".
-
In the Class defaults, navigate to Classes > Default Pawn Class, and select the BP_ExampleCharacter.
-
Compile and Save.
-
Navigate to Edit > Project Settings > Maps and Modes. Set the Default GameMode to BP_InputGameMode.
-
Navigate to the Editor and select Play (Play in Editor)
You can now control your character's movement using the W, A, S, D keys. Moving the mouse moves the camera, and pressing the spacebar causes the character to jump.
Result
