UInputMappingContext
#include "InputMappingContext.h" Description
A data asset that maps UInputAction assets to physical keys, buttons, or axes. Multiple contexts can be active simultaneously at different priority levels, enabling context-sensitive input (on foot vs. in vehicle, gameplay vs. UI).
Caveats & Gotchas
- • Contexts are applied via UEnhancedInputLocalPlayerSubsystem::AddMappingContext. Failing to add a context means no inputs will fire, even if BindAction is called correctly.
- • Higher priority contexts (higher integer value) take precedence. If two active contexts map the same key, only the higher priority mapping fires.
- • Changes to a UInputMappingContext asset at runtime (adding/removing mappings) require calling RebuildControlMappings on the subsystem to take effect.
Example
Define and apply in BeginPlay C++
// In AMyCharacter.h
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input)
TObjectPtr<UInputMappingContext> DefaultMappingContext;
// In AMyCharacter::BeginPlay()
if (APlayerController* PC = Cast<APlayerController>(Controller))
{
if (UEnhancedInputLocalPlayerSubsystem* Sub =
ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PC->GetLocalPlayer()))
{
Sub->AddMappingContext(DefaultMappingContext, 0);
}
} Tags
Version History
Introduced in: 5.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?