포스트

TIL 2026-03-24

TIL 2026-03-24

3/24 - Unreal Engine 5.5 Enhanced Input + 카메라 이동 구현

생성일: 2026년 3월 24일 오후 6:26

작업 목표

  • VOIDBaseCharacter에 탑다운 카메라 추가
  • WASD 카메라 시점 기준 이동 + Space 점프 구현
  • Enhanced Input System 완전 적용 (레거시 입력 제거)

구현 내용

1. 카메라 컴포넌트 추가 (VOIDBaseCharacter)

SpringArmComponent + CameraComponent 조합으로 탑다운 카메라 구성

  • CameraBoom: RootComponent에 부착, 길이 800, Pitch -60도 (탑다운 각도)
  • FollowCamera: CameraBoom 소켓에 부착, 폰 컨트롤 회전 비활성화
  • 카메라가 고정되어 회전하지 않는 탑다운 시점

2. Enhanced Input 클래스 구조

클래스부모역할
USC_MoveActionUInputActionValueType = Axis2D (Vector2D), WASD 이동용
USC_JumpActionUInputActionValueType = Boolean, Space 점프용
USC_InputMappingContextUInputMappingContext두 Action을 내부에 자동 생성, WASD+Space 매핑 자동 구성

3. WASD 매핑 구성 (USC_InputMappingContext::BuildDefaultMappings)

Axis2D 기준 키 매핑:

방향모디파이어
W앞 (Y +1)SwizzleAxis YXZ
S뒤 (Y -1)SwizzleAxis YXZ + Negate
D오른쪽 (X +1)없음
A왼쪽 (X -1)Negate
Space점프없음

4. 카메라 기준 이동 로직

1
2
3
4
5
6
const FRotator CameraYaw(0.0f, CameraBoom->GetComponentRotation().Yaw, 0.0f);
const FVector ForwardDir = FRotationMatrix(CameraYaw).GetUnitAxis(EAxis::X);
const FVector RightDir   = FRotationMatrix(CameraYaw).GetUnitAxis(EAxis::Y);

AddMovementInput(ForwardDir, Input.Y);
AddMovementInput(RightDir,   Input.X);

카메라의 Yaw만 추출해 수평 이동 방향으로 변환 → 카메라가 회전해도 이동 방향이 자동으로 따라감


시행착오

시행착오 1 — VOIDPlayerCharacter vs VOIDBaseCharacter

  • 문제: 처음에 VOIDPlayerCharacter에 입력 코드를 작성했으나, 실제 사용 클래스는 VOIDBaseCharacter였음
  • 해결: VOIDBaseCharacter로 이동하여 작업

시행착오 2 — BuildDefaultMappings() 수동 호출 문제

  • 문제: USC_InputMappingContextUObject 기반 데이터 에셋이라 블루프린트에 Construction Script가 없음. BuildDefaultMappings()를 명시적으로 호출하지 않으면 에디터에서도 매핑이 보이지 않고 런타임에도 동작하지 않음
  • 해결: PostLoad()PostEditChangeProperty()를 오버라이드하여 자동 호출
1
2
3
4
5
6
7
8
9
10
11
12
13
void USC_InputMappingContext::PostLoad()
{
    Super::PostLoad();
    BuildDefaultMappings();
}

#if WITH_EDITOR
void USC_InputMappingContext::PostEditChangeProperty(FPropertyChangedEvent& e)
{
    Super::PostEditChangeProperty(e);
    BuildDefaultMappings();
}
#endif

시행착오 3 — Enhanced Input 경고 발생

  • 경고: Axis and Action mappings are now deprecated, please use Enhanced Input Actions and Input Mapping Contexts instead.
  • 원인: DefaultMappingContextMoveAction UPROPERTY가 블루프린트에서 수동 할당되지 않아 null 상태로 Enhanced Input이 실제로 등록되지 않음. 레거시 입력 경로로 빠짐
  • 해결: CreateDefaultSubobject로 생성자에서 자동 생성하여 null 문제 원천 차단
1
2
// VOIDBaseCharacter 생성자
InputMappingContext = CreateDefaultSubobject<USC_InputMappingContext>(TEXT("InputMappingContext"));

시행착오 4 — DefaultInput.ini 확인

  • DefaultPlayerInputClass=/Script/EnhancedInput.EnhancedPlayerInput
  • DefaultInputComponentClass=/Script/EnhancedInput.EnhancedInputComponent
  • 프로젝트 설정은 이미 Enhanced Input으로 되어 있었음 → 문제는 코드 레벨의 null 참조였음

최종 구조 요약

1
2
3
4
5
6
AVOIDBaseCharacter
├── USpringArmComponent (CameraBoom)
├── UCameraComponent (FollowCamera)
└── USC_InputMappingContext (InputMappingContext)
    ├── USC_MoveAction (MoveAction) — Axis2D, WASD 자동 매핑
    └── USC_JumpAction (JumpAction) — Boolean, Space 자동 매핑
  • 블루프린트에서 아무것도 할당하지 않아도 WASD 이동 + Space 점프 자동 동작
  • Build.csEnhancedInput 모듈 추가 필요
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.