Input Mapping Context와 Subsystem
Enhanced Input의 Context는 UEnhancedInputLocalPlayerSubsystem이 관리한다.
이 Subsystem은 ULocalPlayerSubsystem이기 때문에 플레이어 단위로 존재한다.
UGameInstance
└─ ULocalPlayer
└─ UEnhancedInputLocalPlayerSubsystem
└─ UEnhancedPlayerInput
| 구조 장점 장점 | 설명 |
|---|---|
| 플레이어별 독립성 | 로컬 플레이어마다 별도 입력 시스템을 가짐 |
| Possess 변경에 강함 | 캐릭터가 바뀌어도 LocalPlayer 기준 입력 상태 유지 가능 |
| Context 동적 전환 가능 | 메뉴, 전투, 차량 탑승 등 상황별 입력 전환 가능 |
Subsystem 접근 예시
void UContextManagerComponent::InitializeSubsystem()
{
AActor* Owner = GetOwner();
APlayerController* PC = Cast<APlayerController>(Owner->GetInstigatorController());
if (!PC)
{
return;
}
ULocalPlayer* LocalPlayer = PC->GetLocalPlayer();
if (!LocalPlayer)
{
return;
}
CachedSubsystem =
ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(LocalPlayer);
}
Actor
↓
PlayerController
↓
LocalPlayer
↓
UEnhancedInputLocalPlayerSubsystem
게임 시작 직후나 AI 캐릭터에서는 PlayerController가 없을 수 있으므로 null 체크해야함
Priority System
Input Mapping Context는 Priority를 기준으로 처리된다.
높은 Priority를 가진 Context가 먼저 평가된다.
Subsystem->AddMappingContext(IMC_Menu, 100);
Subsystem->AddMappingContext(IMC_Combat, 50);
Subsystem->AddMappingContext(IMC_Default, 0);
처리 예시
| 순서 | IMC | Priority | ConsumeInput | 결과 |
|---|---|---|---|---|
| 1 | IMC_UI | 100 | true | UI 입력 처리 후 게임 입력 차단 |
| 2 | IMC_Combat | 50 | false | UI가 소비하지 않은 입력 처리 |
| 3 | IMC_Default | 0 | false | 기본 입력 처리 |
ConsumeInput이 true라면 해당 입력은 하위 Context로 전달되지 않는다.
UI 열기 / 닫기 예시
void OpenMenu()
{
Subsystem->AddMappingContext(IMC_Menu, 100);
}
void CloseMenu()
{
Subsystem->RemoveMappingContext(IMC_Menu);
}
| 상태 | 활성 Context |
|---|---|
| 기본 상태 | IMC_Default(0) |
| 메뉴 열림 | IMC_Menu(100), IMC_Default(0) |
| 메뉴 닫힘 | IMC_Default(0) |
ContextManager Component
엔진의 Subsystem은 IMC 객체와 Priority만 관리한다.
게임 코드에서 ContextManagerComponent를 두고 레이어를 추가할 수 있다.
USTRUCT()
struct FActiveContext
{
EGameplayContext Context;
UInputMappingContext* MappingContext;
float ActivationTime;
};
UCLASS()
class UContextManagerComponent : public UActorComponent
{
GENERATED_BODY()
private:
TArray<FActiveContext> ContextStack;
UPROPERTY()
UEnhancedInputLocalPlayerSubsystem* CachedSubsystem;
UPROPERTY()
TMap<EGameplayContext, UInputMappingContext*> ContextMappings;
};
ContextManager의 역할
| 역할 | 설명 |
|---|---|
| enum 기반 Context 관리 | EGameplayContext로 현재 상황을 명확히 표현 |
| 중복 Context 방지 | 같은 IMC가 여러 번 등록되는 문제 방지 |
| Stack 기반 전환 | 마지막으로 들어온 Context를 우선 처리 |
| 현재 Context 조회 | 외부 시스템에서 현재 상황 확인 가능 |
| 엔진 레이어와 게임 레이어 분리 | IMC 객체 직접 의존 감소 |
Priority 전략
모든 Context를 Priority 0으로 추가하면 처리 순서를 예측하기 어렵다.
CachedSubsystem->AddMappingContext(IMC, 0);
따라서 Stack 크기를 Priority로 사용하는 전략을 쓸 수 있다.
int32 Priority = ContextStack.Num();
CachedSubsystem->AddMappingContext(IMC, Priority);
| Context | Priority | 의미 |
|---|---|---|
| Default | 0 | 기본 입력 |
| FloorCleaning | 1 | 기본보다 우선 |
| WindowCleaning | 2 | 가장 최근 Context, 최우선 |
이 방식은 가장 최근에 추가된 Context가 가장 높은 우선순위를 갖게 한다.
[Default]
↓ Push FloorCleaning
[Default, FloorCleaning]
↓ Push WindowCleaning
[Default, FloorCleaning, WindowCleaning]
↓ Pop
[Default, FloorCleaning]반응형
'Unreal Engine' 카테고리의 다른 글
| UE Input 3 (0) | 2026.06.25 |
|---|---|
| UE Input 2 (0) | 2026.06.24 |
| GameplayTag Static vs GameplayTag Extern (0) | 2026.06.22 |
| AssetManager (0) | 2026.06.19 |
| UE Game play Framework 2 (0) | 2026.06.18 |