2026-04-15 언리얼 강의 및 과제 준비
목차
챕터 2-1 — GameMode & 캐릭터 기초
GameMode란?
게임의 규칙·흐름을 관리하는 컨트롤 타워. 플레이어 수, 승패 조건 등 설정.
AGameMode : 멀티플레이어 전용 (로그인/재시작 등 추가 기능)AGameModeBase : 기본형 (싱글 프로젝트에 주로 사용)
핵심 프로퍼티
1
2
3
| // DefaultPawnClass : 플레이어가 빙의할 Pawn 클래스 지정
// PlayerControllerClass : 입력 처리 담당 컨트롤러 클래스 지정
DefaultPawnClass = ASpartaCharacter::StaticClass();
|
Pawn vs Character
| 항목 | Pawn | Character |
|---|
| 이동 컴포넌트 | 없음 (직접 구현) | UCharacterMovementComponent 내장 |
| 중력 / 점프 | 없음 | 자동 처리 |
| 자유도 | 높음 (비행체·탈것 등) | 낮음 (인간형 캐릭터 최적화) |
컴포넌트 구성
1
2
3
4
| // Root: CapsuleComponent
// SkeletalMeshComponent — SKM_Manny, Yaw -90° 보정
// SpringArmComponent — bUsePawnControlRotation = true
// CameraComponent — bUsePawnControlRotation = false (SpringArm이 대신 회전)
|
PlayerController 역할
입력 이벤트를 받아 → Pawn에 전달하는 중간 레이어. ASpartaPlayerController 생성 후 GameMode에 PlayerControllerClass 등록.
| 에셋 | 역할 | 예시 |
|---|
| Input Action (IA) | 단일 입력 정의 | IA_Move (Axis2D), IA_Jump (Bool) |
| Input Mapping Context (IMC) | IA ↔ 키 바인딩 묶음 | IMC_Character |
WASD 매핑 — Modifier 조합
1
2
3
4
5
| W → X+ (기본값)
S → X+ + Negate (X 반전)
A → Y+ + Swizzle + Negate (Y축으로 이동 후 반전)
D → Y+ + Swizzle (Y축으로 이동)
마우스 Y → Negate (위 = 카메라 위)
|
IMC 활성화 (BeginPlay)
1
2
3
4
5
6
| if (auto* PC = Cast<ASpartaPlayerController>(GetController()))
{
if (auto* Sub = PC->GetLocalPlayer()
->GetSubsystem<UEnhancedInputLocalPlayerSubsystem>())
Sub->AddMappingContext(InputMappingContext, 0);
}
|
챕터 2-3 — 입력 바인딩 & 이동 함수 구현
1
2
3
4
5
6
7
8
9
| if (auto* EIC = Cast<UEnhancedInputComponent>(PlayerInputComponent))
{
EIC->BindAction(MoveAction, ETriggerEvent::Triggered, this, &ASpartaCharacter::Move);
EIC->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ASpartaCharacter::StartJump);
EIC->BindAction(JumpAction, ETriggerEvent::Completed, this, &ASpartaCharacter::StopJump);
EIC->BindAction(LookAction, ETriggerEvent::Triggered, this, &ASpartaCharacter::Look);
EIC->BindAction(SprintAction, ETriggerEvent::Triggered, this, &ASpartaCharacter::StartSprint);
EIC->BindAction(SprintAction, ETriggerEvent::Completed, this, &ASpartaCharacter::StopSprint);
}
|
함수 구현
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| // Move
void Move(const FInputActionValue& Value)
{
FVector2D V = Value.Get<FVector2D>();
AddMovementInput(GetActorForwardVector(), V.X);
AddMovementInput(GetActorRightVector(), V.Y);
}
// Look
void Look(const FInputActionValue& Value)
{
FVector2D V = Value.Get<FVector2D>();
AddControllerYawInput(V.X);
AddControllerPitchInput(V.Y);
}
// Sprint
void StartSprint() { GetCharacterMovement()->MaxWalkSpeed = SprintSpeed; } // 900
void StopSprint() { GetCharacterMovement()->MaxWalkSpeed = NormalSpeed; } // 600
|
챕터 2-4 — 애니메이션 State Machine
Animation Blueprint State Machine 개요
캐릭터 동작(Idle / Walk / Run / Jump / Fall)을 상태(State) 와 전환 조건(Transition) 으로 설계.
주요 변수
1
2
3
| // AnimBP에서 매 프레임 업데이트
float Speed; // GetVelocity().Size2D()
bool bIsInAir; // GetMovementComponent()->IsFalling()
|
상태 전환 흐름
1
2
3
4
5
| Idle ──(Speed > 0)──► Walk ──(Speed > 600)──► Run
▲ │
└──────────────(Speed == 0)────────────────────┘
Idle/Walk/Run ──(bIsInAir)──► Jump ──(!bIsInAir)──► Idle
|
적용 포인트
- AnimBP의
NativeUpdateAnimation에서 Pawn 레퍼런스 캐스팅 → 변수 갱신 - Blend Space 사용 시 Speed 축으로 Idle~Walk~Run 부드럽게 보간