1. PlayerController 개념 정리
PlayerController란?
PlayerController는 키보드, 마우스, 게임패드 등에서 들어오는 입력을 해석해 Pawn(캐릭터)에게 명령을 전달하는 클래스다.
언리얼 엔진의 핵심 설계 철학 중 하나는 입력 처리는 PlayerController에서, 실제 동작은 Pawn에서 처리하도록 분리하는 것이
다.
입력 처리 흐름
- 입력 장치에서 입력 발생
- PlayerController가 입력을 수신 및 해석
- Possess 중인 Pawn에게 이동, 회전, 점프 등의 명령 전달
멀티플레이 환경에서는 플레이어마다 PlayerController가 개별 생성되어 입력이 서로 분리된다.
주요 역할
- 입력 처리 (Enhanced Input 시스템 사용)
- 카메라 제어
- HUD / UI 이벤트 처리
- Pawn Possess / UnPossess 관리
2. PlayerController C++ 클래스 생성 및 적용
C++ PlayerController 생성
- PlayerController를 상속받아 ASpartaPlayerController 생성
- 기본 구조만 가진 클래스부터 시작
UCLASS()
class SAMPLEPROJECT_API ASamplePlayerController : public APlayerController
{
GENERATED_BODY()
};
GameMode에 PlayerController 등록
GameMode는 사용할 Pawn과 PlayerController를 결정한다.
ASampleGameMode::ASampleGameMode()
{
DefaultPawnClass = ASampleCharacter::StaticClass();
PlayerControllerClass = ASamplePlayerController::StaticClass();
}
이렇게 설정하면 게임 시작 시 커스텀 PlayerController가 자동으로 생성된다.
Blueprint 래핑
- C++ PlayerController를 기반으로 Blueprint 생성
- 이후 입력 에셋(IMC, IA)을 에디터에서 할당 가능
3. Enhanced Input System 개념
UE5에서는 기존 Input 시스템을 확장한 Enhanced Input System을 사용한다.
핵심 구성 요소
- Input Action (IA): 하나의 동작 단위 (이동, 점프 등)
- Input Mapping Context (IMC): 여러 IA를 묶은 입력 세트
상황에 따라 IMC를 활성/비활성하여 입력 모드를 전환할 수 있다.
4. Input Action 설계
IA 예시
- IA_Move: 이동 (Axis2D)
- IA_Jump: 점프 (Bool)
- IA_Look: 시점 회전 (Axis2D)
- IA_Sprint: 달리기 (Bool)
Value Type 기준
- Bool: 단순 On/Off 입력
- Axis1D: 한 방향 축 입력
- Axis2D: 이동, 마우스 회전
- Axis3D: 3축 제어
5. Input Mapping Context 설정
IMC 생성
- IMC_Character 생성
- IA_Move, IA_Jump, IA_Look, IA_Sprint 추가
이동 키 매핑
- W / S → X축 (+ / -)
- A / D → Y축 (- / +)
- Swizzle + Negate로 축 정렬
Look 설정
- 마우스 X → Yaw
- 마우스 Y → Pitch
- Pitch는 좌표계 차이로 Negate 적용
6. PlayerController에서 IMC 활성화
입력 에셋 변수 선언
C++에서 IMC와 IA를 멤버 변수로 선언해 에디터에서 할당 가능하게 한다.
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Input")
UInputMappingContext* InputMappingContext;
BeginPlay에서 IMC 활성화
Enhanced Input은 Local Player Subsystem을 통해 관리된다.
void ASamplePlayerController::BeginPlay()
{
Super::BeginPlay();
if (ULocalPlayer* LocalPlayer = GetLocalPlayer())
{
if (UEnhancedInputLocalPlayerSubsystem* Subsystem =
LocalPlayer->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>())
{
if (InputMappingContext)
{
Subsystem->AddMappingContext(InputMappingContext, 0);
}
}
}
}
정리
- GetLocalPlayer(): 현재 PlayerController의 Local Player
- EnhancedInputLocalPlayerSubsystem: IMC 관리 주체
- AddMappingContext(): IMC 활성화 (Priority 낮을수록 우선)
7. 동작 확인
- Blueprint에서 Enhanced Action Event 노드 검색 가능
- IA_Move, IA_Jump, IA_Look 이벤트 정상 호출 확인
- Print String 등으로 입력 테스트 가능
오늘의 정리
- PlayerController는 입력 처리의 중심
- Pawn과 입력 로직을 분리하면 구조가 깔끔해진다
- Enhanced Input은 IA + IMC 구조로 확장성과 관리성이 좋다
- IMC는 PlayerController의 Local Player Subsystem에서 활성화한다
- 입력 설계는 초기에 잘 잡아두면 이후 확장이 편하다
'내배캠 TIL' 카테고리의 다른 글
| [내배캠 TIL 260121] UnrealEngine 블루프린트와 C++ 우선순위, 맵 저장 오류, 카메라 회전 직접 구현 (0) | 2026.01.21 |
|---|---|
| [내배캠 TIL 260120] Unreal Pawn 클래스로 캐릭터 Move 구현 (0) | 2026.01.20 |
| [내배캠 TIL 260112] Unreal Timer를 활용한 액터 생성 (0) | 2026.01.13 |
| [내배캠 TIL 260112] Unreal c++을 활용한 액터의 이동과 회전 (0) | 2026.01.12 |
| [내배캠 TIL 260109] Unreal 액터의 생명주기 (0) | 2026.01.09 |