{ }Blueprint → C++

Unreal Engine 5 · Blueprint → C++

Add Input Mapping Context in Unreal Engine 5 C++UE Docs

The Add Mapping Context Blueprint node maps to UEnhancedInputLocalPlayerSubsystem::AddMappingContext in C++. You grab the subsystem from the local player and register a UInputMappingContext with a priority value, usually in BeginPlay.

Blueprint node & C++ equivalent

Header (.h)
UPROPERTY(EditAnywhere, Category="Input")
UInputMappingContext* DefaultMappingContext;
BeginPlay (.cpp)
#include "EnhancedInputSubsystems.h"

if (APlayerController* PC = Cast<APlayerController>(GetController()))
{
  if (UEnhancedInputLocalPlayerSubsystem* Subsystem =
      ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer()))
  {
    Subsystem->AddMappingContext(DefaultMappingContext, /*Priority=*/0);
  }
}

What does the Add Mapping Context node do?

The Add Mapping Context node activates a set of input mappings for a player. Until a UInputMappingContext is added, the Enhanced Input system ignores the keys it defines, so this is the step that turns your mappings on. Higher priority contexts can override lower ones when keys overlap.

The C++ equivalent

Declare the context as a UPROPERTY(EditAnywhere, Category="Input") of type UInputMappingContext* so you can assign the asset in the editor. In code you include EnhancedInputSubsystems.h, cast the controller to APlayerController, then call ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer()). Finally call Subsystem->AddMappingContext(DefaultMappingContext, 0) where the second argument is the priority.

Where to call it

Place this in BeginPlay so the context is added once the pawn is possessed and the controller exists. The nested if checks guard against null controllers and a missing subsystem, which prevents crashes on dedicated servers or before possession. The DefaultMappingContext must be set in a Blueprint subclass or it will be null.

Frequently asked questions

How do I get the Enhanced Input subsystem in C++?+

Cast the controller to APlayerController, then call ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer()). Include EnhancedInputSubsystems.h first.

What is the priority argument in AddMappingContext?+

It is an integer that resolves conflicts when multiple contexts bind the same key. A higher priority context takes precedence; 0 is a common default for a single gameplay context.

Where should I call AddMappingContext?+

Usually in BeginPlay after the pawn is possessed so a valid APlayerController and local player exist. You can also add or remove contexts later to switch input modes.

Related Input (Enhanced Input) nodes

View all Input (Enhanced Input) nodes →