ftftgop3 2024. 2. 4. 14:45

엔진에서 작업 구분

레벨를 구성, 게임플레이를 설계

앞의 예제 분수는 레벨을 구성하는 예제

 

게임 모드

게임 규칙을 관리 및 게임에서는 심판에 역할

플레이어가 조종할 액터를 생성 및 전달하는 역할

 

플레이어가 조종하는 액터 

 

시작 레벨 변경 방법

프로젝트 설정 → 맵&모드 → Default Maps 섹션에 설정

Selected GameMode → default Pawn class →  폰 변경 

 

게임 모드 생성 및 폰 생성  

파일 → 새로운 C++ 클래스 → GamModeBase 클래스

파일 → 새로운 C++ 클래스 → Pawn 클래스

 

게임 모드를 레벨에 적용

툴바 셋팅 → 월드 세팅 →  GameMode 변경

 

게임모드에 Pawn 지정 방법

언리얼 오브젝트의 클래스 정보는 언리얼 헤더 툴에 의해 자동 생성

언리얼 오브젝트 마다 자동으로 생성 되는 StaticClass 라는 스태틱 함수 호출

#include "ABPawn.h"

AABGameMode::AABGameMode()
{
	DefaultPawnClass = AABPawn::StaticClass();
}

 

 

플레이어 컨트롤러

게임 모드에서 플레이어 입장 시 배정

플레이어와 소통 하며 폰을 조종 하는 역할

배정된 플레이어 컨트롤러는 변경 할 수 없다

 

플레이어 컨트롤러에 조종 당하는 엑터

플레이어 컨트롤러로 현재 폰을 버리고 다른 폰으로 Possess 하여 사용

 

Possess(빙의)

플레이어 컨트롤러 가 폰을 조종하는 행위

 

게임 모드에서 플레이어 입장 시 처리 순서

플레이어 입장이라는 건 플레이 버튼을 누른것 으로 지정 

1. 플레이어 컨트롤러 생성

2. 플레이어 폰 생성

3. 컨트롤러가 폰에 빙의

4. 게임 시작

 

게임모드에 ABPlaycontroller 클래스 변경

#include "ABPawn.h"
#include "ABPlayerController.h"

AABGameMode::AABGameMode()
{
	DefaultPawnClass = AABPawn::StaticClass();
	PlayerControllerClass = AABPlayerController::StaticClass();
}

 

 

플레이어 초기화 과정 순서

플레이어의 입장을 로그인이라 하며 PostLogin 이벤트 함수 호출

함수 내부에서는 폰, 플레이어 컨트롤러가 빙의 하는 작업 

 

폰과 플레이어 컨트롤러 생성 되는 시점 

PostInitializeComponents() 파악

 

빙의 진행 시점

플레이어 컨트롤러의 Possess () 

폰의 PossessedBy() 파악

 

로그로 생성 및 빙의 시점 순서 파악

void AABGameMode::PostLogin(APlayerController* NewPlayer)
{
	ABLOG(Warning, TEXT("PostLogin Begin"));
	Super::PostLogin(NewPlayer);
	ABLOG(Warning, TEXT("PostLogin End"));
}

ArenaBattle: Warning: AABGameMode::PostInitializeComponents(31)
LogWorld: Bringing up level for play took: 0.001070
ArenaBattle: Warning: AABPlayerController::PostInitializeComponents(8)
ArenaBattle: Warning: AABGameMode::PostLogin(23) PostLogin Begin
ArenaBattle: Warning: AABPawn::PostInitializeComponents(31)
ArenaBattle: Warning: AABPlayerController::Possess(13)
ArenaBattle: Warning: AABPawn::PossessedBy(36)
ArenaBattle: Warning: AABGameMode::PostLogin(25) PostLogin End

 

폰의 Auto Possess Player

위에 방식은 멀티 플레이 게임에 적합 예외적인 설정도 가능

이미 배치돼 있는 폰에 플레이어 컨트롤러가 빙의

Auto Possess Player 항목을 Player 0 설정 ( 로컬 플레이어) 

 

블루 프린트로 제작된 폰을 기본 폰으로 사용

에셋 경로에 _C 접미사를 붙여서 사용, 블루 프린트를 가지고 올때는 _C 사용 

AABGameMode::AABGameMode()
{
	//DefaultPawnClass = AABPawn::StaticClass();
	PlayerControllerClass = AABPlayerController::StaticClass();


	static ConstructorHelpers::FClassFinder<APawn> BP_PAWN_C
    (TEXT("/Game/ThirdPersonBP/Blueprints/ThirdPersonCharacter.ThirdPersonCharacter_C"));

	if (BP_PAWN_C.Succeeded())
	{
		DefaultPawnClass = BP_PAWN_C.Class;
	}
}