Enhanced Input
Enhanced Input is UE5's input system (a plugin, enabled by default; the old Action/Axis mappings in Project Settings are deprecated). It separates what the player wants to do from which key they press:
| Asset | What it is | Example |
|---|---|---|
Input Action (UInputAction) |
an intention with a value type: bool, Axis1D, Axis2D, Axis3D |
IA_Move (Axis2D), IA_Jump (bool), IA_Dash (bool) |
Input Mapping Context (UInputMappingContext) |
a set of key → action mappings, with modifiers and triggers per mapping | IMC_Default: WASD and the left stick → IA_Move; Space and gamepad A → IA_Jump |
| Modifier | transforms the raw value | Dead Zone, Negate, Swizzle Input Axis Values (turn W's X into Y), Scalar |
| Trigger | decides when the action fires | Pressed, Released, Hold, Hold And Release, Tap, Pulse, Chorded Action |
Mapping contexts are added and removed at runtime with a priority: add IMC_Vehicle with a higher priority when the player gets in a car, and its mappings win over IMC_Default for the keys they share.
Editor steps
- Content Browser → Add → Input → Input Action: create
IA_Move(Value Type Axis2D),IA_Look(Axis2D),IA_Jump(Digital (bool)),IA_Dash(Digital (bool)). - Add → Input → Input Mapping Context: create
IMC_Default. Add mappings:IA_Move: W with Swizzle Input Axis Values (YXZ); S with Swizzle + Negate; A with Negate; D with nothing; Gamepad Left Thumbstick 2D-Axis with Dead Zone.IA_Look: Mouse XY 2D-Axis with Negate (Y only); Gamepad Right Thumbstick 2D-Axis with Dead Zone.IA_Jump: Space Bar, Gamepad Face Button Bottom.IA_Dash: Left Shift with a Pressed trigger.
- In
BP_ArenaCharacter's class defaults, assign the assets to the C++ properties below.
C++ setup
Add "EnhancedInput" to Build.cs.
// ArenaCharacter.h (additions)
class UInputMappingContext;
class UInputAction;
struct FInputActionValue;
UCLASS()
class ARENA_API AArenaCharacter : public ACharacter
{
GENERATED_BODY()
protected:
virtual void NotifyControllerChanged() override;
virtual void SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) override;
void Move(const FInputActionValue& Value);
void Look(const FInputActionValue& Value);
void Dash();
UPROPERTY(EditDefaultsOnly, Category = "Input")
TObjectPtr<UInputMappingContext> DefaultMappingContext;
UPROPERTY(EditDefaultsOnly, Category = "Input")
TObjectPtr<UInputAction> MoveAction;
UPROPERTY(EditDefaultsOnly, Category = "Input")
TObjectPtr<UInputAction> LookAction;
UPROPERTY(EditDefaultsOnly, Category = "Input")
TObjectPtr<UInputAction> JumpAction;
UPROPERTY(EditDefaultsOnly, Category = "Input")
TObjectPtr<UInputAction> DashAction;
};// ArenaCharacter.cpp (additions)
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "InputActionValue.h"
void AArenaCharacter::NotifyControllerChanged()
{
Super::NotifyControllerChanged();
// Add the mapping context for the local player whenever a player controller possesses us.
if (APlayerController* PC = Cast<APlayerController>(Controller))
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem =
ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer()))
{
Subsystem->AddMappingContext(DefaultMappingContext, /*Priority*/ 0);
}
}
}
void AArenaCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
UEnhancedInputComponent* Input = CastChecked<UEnhancedInputComponent>(PlayerInputComponent);
Input->BindAction(JumpAction, ETriggerEvent::Started, this, &ACharacter::Jump);
Input->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
Input->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AArenaCharacter::Move);
Input->BindAction(LookAction, ETriggerEvent::Triggered, this, &AArenaCharacter::Look);
Input->BindAction(DashAction, ETriggerEvent::Triggered, this, &AArenaCharacter::Dash);
}
void AArenaCharacter::Move(const FInputActionValue& Value)
{
const FVector2D Axis = Value.Get<FVector2D>(); // X = right, Y = forward
const FRotator YawOnly(0.f, Controller->GetControlRotation().Yaw, 0.f);
const FVector Forward = FRotationMatrix(YawOnly).GetUnitAxis(EAxis::X);
const FVector Right = FRotationMatrix(YawOnly).GetUnitAxis(EAxis::Y);
AddMovementInput(Forward, Axis.Y);
AddMovementInput(Right, Axis.X);
}
void AArenaCharacter::Look(const FInputActionValue& Value)
{
const FVector2D Axis = Value.Get<FVector2D>();
AddControllerYawInput(Axis.X);
AddControllerPitchInput(Axis.Y);
}ETriggerEvent tells you which phase you're bound to: Started (the first frame the trigger begins), Ongoing (e.g. while a Hold hasn't reached its time yet), Triggered (the action fires; every frame for continuous input), Completed (released after triggering) and Canceled (released before triggering, e.g. a Hold let go too early).
Older templates add the mapping context in BeginPlay. That works until the pawn is possessed after BeginPlay (respawning, possession switching). NotifyControllerChanged (an APawn hook since UE 5.0, used by recent 5.x templates) or the PlayerController's OnPossess covers those cases.
Tip: Console command
showdebug enhancedinputdisplays active mapping contexts, actions and their current values during play. Use it whenever "the key doesn't work".
A model: modifiers, triggers and priorities
This model processes a few frames of key input the way Enhanced Input does: each key's raw value goes through its mapping's modifiers, contributions to the same action are summed, a trigger turns the value into events, and a higher-priority context hides lower-priority mappings of the same key.
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <string>
#include <vector>
struct V2 { double x = 0, y = 0; };
enum Mod { Swizzle, Negate };
struct Mapping { std::string Key, Action; std::vector<Mod> Mods; };
struct Context { std::string Name; int Priority; std::vector<Mapping> Maps; };
V2 Apply(V2 v, const std::vector<Mod>& mods) {
for (Mod m : mods) {
if (m == Swizzle) std::swap(v.x, v.y);
if (m == Negate) { v.x = -v.x; v.y = -v.y; }
}
return v;
}
int main() {
std::cout << std::fixed << std::setprecision(0);
Context def{"IMC_Default", 0, {{"W", "IA_Move", {Swizzle}}, {"S", "IA_Move", {Swizzle, Negate}},
{"A", "IA_Move", {Negate}}, {"D", "IA_Move", {}}, {"Space", "IA_Jump", {}}}};
Context car{"IMC_Vehicle", 1, {{"Space", "IA_Handbrake", {}}, {"W", "IA_Throttle", {Swizzle}}}};
std::vector<std::set<std::string>> frames = {{"W"}, {"W", "D"}, {"W", "S"}, {"Space"}, {"Space"}, {}, {"Space", "W"}};
std::vector<const Context*> active = {&def};
std::map<std::string, bool> wasDown;
for (size_t f = 0; f < frames.size(); f++) {
if (f == 6) active.push_back(&car); // the player enters a vehicle
std::map<std::string, V2> value;
std::set<std::string> claimed; // keys taken by a higher priority context
for (int pr = 1; pr >= 0; pr--)
for (const Context* c : active) {
if (c->Priority != pr) continue;
for (const auto& m : c->Maps) {
if (claimed.count(m.Key)) continue;
value[m.Action]; // the action exists even with no input
if (frames[f].count(m.Key)) {
V2 v = Apply({1, 0}, m.Mods); // a digital key gives (1, 0)
value[m.Action].x += v.x; value[m.Action].y += v.y;
}
}
for (const auto& m : c->Maps) claimed.insert(m.Key);
}
std::cout << "frame " << f + 1 << ":";
for (auto& [action, v] : value) {
bool down = v.x != 0 || v.y != 0;
if (action == "IA_Move" && down) std::cout << " IA_Move Triggered (" << v.x << ", " << v.y << ")";
else if (action != "IA_Move") { // a Pressed trigger: one event per press
if (down && !wasDown[action]) std::cout << " " << action << " Started+Triggered";
if (!down && wasDown[action]) std::cout << " " << action << " Completed";
}
wasDown[action] = down;
}
std::cout << "\n";
}
}frame 1: IA_Move Triggered (0, 1)
frame 2: IA_Move Triggered (1, 1)
frame 3:
frame 4: IA_Jump Started+Triggered
frame 5:
frame 6: IA_Jump Completed
frame 7: IA_Handbrake Started+Triggered IA_Throttle Started+Triggered
Frame 3 shows W and S cancelling out to no movement. Frame 5 shows that holding Space doesn't re-fire a Pressed action, and frame 7 shows the vehicle context taking over Space and W.
Test yourself
What is an Input Mapping Context?
- A single key binding
- A set of key-to-action mappings that can be added or removed at runtime with a priority
- A Blueprint graph
- A replacement for the PlayerController
Why does W need a Swizzle modifier when mapped to a 2D move action?
- W is analog
- A key produces a value on X; swizzling moves it to Y (forward)
- To invert it
- To add a dead zone
A Hold trigger was released before its hold time. Which ETriggerEvent fires?
- Triggered
- Completed
- Canceled
- Started