]: When?
Player Input에 따른 Action을 수행할 때, 사용한다.
]: Why?
이전 Unreal InputSystem이었던 BindAxis에서 유연한 입력에 대한 처리에 대한 필요성으로 인하여, Enhanced Input이 등장했다.
Platform간의 입력에 대한 전환도 유연하게 할 수 있다.
Trigger Option으로 아래와 같은 Chorded Action을 통해 복합 키 입력에 대해 대응이 가능하다.
]: How?
}: Input Action
Input Action은 ValueType, Trigger, Modifier로 구성된다.
- Value Type : 입력에 대한 반환 값이, 어떤 Type일지 결정한다. bool, Vector1,2,3d가 지원된다.
- Trigger : 입력에 대해서, Pressed, Down, Released와 같이 어떤 상황에 Input Action이 활성화될지 결정한다.
- Modifier : Value Type을 어떻게 변화시킬지에 대해 결정한다. Negate, Swizzle Axis...
}: Input Mapping Context
LocalPlayer Subsystem에 등록되는 Key - InputAction의 모음이다.
여기서 InputAction에 대한 Key를 지정한다.
InputAction의 Setting에 대해 추가하거나, override할 수 있다.
}: Native
1. Mapping Context 등록
LocalPlayerSubsystem에서 Enhanced Input을 관장하므로, IMC를 등록한다.
// PlayerController->SetInputComponent
auto EISubSystem{GetLocalPlayer()->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>()};
EISubSystem->AddMappingContext(IMC, 0);
2. BindAction
InputAction에 대해, 실행할 함수와 Binding 해준다.
if(auto EIComp{Cast<UEnhancedInputComponent>(InputComponent)})
{
EIComp->BindAction(IA_Look, ETriggerEvent::Triggered, this, &ThisClass::Input_Look);
}
3. Call Function
Binding하는 함수는 const FInputActionValue& 를 매개변수로 받아야 한다.
- FInputActionValue에서 Get함수로 원하는 Type을 가져와, 내부 로직에 사용할 수 있다.
- 추가적인 매개변수도 받을 수 있다.
void ASH_PlayerController::Input_Look(const FInputActionValue& InputActionValue)
{
FVector2D Value{InputActionValue.Get<FVector2D>()};
if(Value.X != 0.f)
{
AddYawInput(Value.X);
}
if(Value.Y != 0.f)
{
AddPitchInput(-Value.Y);
}
}
// 추가적인 매개변수
EIComp->BindAction(IA, ETriggerEvent::Triggered, this, &ThisClass::Input_ActivateAbilityWithTag, IA->GetAbilityTag());
void Input_ActivateAbilityWithTag(const FInputActionValue& InputActionValue, FGameplayTag InTag)
}: 키 변경
IMC->UnmapKey(IA_Jump, FKey(EKeys::SpaceBar));
IMC->MapKey(IA_Jump, FKey(EKeys::A));
Map, Unmap Keyword로 Action 그 자체나, Action에서의 Key를 추가하거나 삭제할 수 있다.
!!! 주의 !!!
Input Mapping Context는 DataAsset이다.
따라서 IMC UnmapKey, MapKey를 통해 Runtime중 Key를 변경하면, IMC DataAsset자체도 변화하게 된다.
의도에 따라, 잘 사용해야 한다.