Lyra Sample 을 분석하다보니, UGameFrameworkComponentManager 를 사용해서 컴포넌트의 초기화 순서를 결정하고 있었다.
ModularCharacter 등 클래스를 만들어서 초기화 순서를 관리할 액터들을 Register 하고 Handling 하는 부분이 나오길래
왜 컴포넌트들의 순서를 확실하게 분리하고 결정하려고 하는지 알아야 했다.
그래서 이전에 엔진의 시작부터 모든 액터들의 BeginPlay 까지의 흐름을 정리하려고 한다.
게임 엔진 플로우
- UGameEngine::Init
- UGameInstance::Init
- InitCreateUOnlineSession
- UGameEngine::Start
- UGameInstance::StartGameInstance()
- UEngine::LoadMap()
- UWorld::InitializeActorsForPlay
- UActorComponent::RegisterComponent
- 모든 액터들의 컴포넌트를 World 에 등록
- 컴포넌트들은 OnRegister 함수 호출됨.
- 컴포넌트가 모두 등록되면 GameMode의 InitGame 호출
- UActorComponent::RegisterComponent
- GameMode 생성
- GameMode::InitGame
- Game Session Actor 생성
- World가 각 Level 별 루프를 돌면서 각 레벨의 Actor 초기화
- ULevel::RouteActorInitialize() — 모든 액터 대상으로 초기화 진행
- Actor::PreInitializeComponents() — 초기화 전
- GameMode::PreInitializeComponents
- GameState 생성
- GameState::PreInitializeComponents
- GameState::InitGameState 호출
- GameMode::PreInitializeComponents
- Actor::InitializeComponent — 초기화
- bAutoActive true 면 활성화
- bWantInitializeComponent 면 해당 컴포넌트 초기화
- Actor::PostInitializeComponents() — 초기화 후
- 컴포넌트들이 다 초기화 된 후 완전한 상태에 있을때에 호출되는 가장 초기 지점
- GameState::PostInitializeComponents
- GameMode::PostInitializeComponents
- Actor::PreInitializeComponents() — 초기화 전
- LoadMap 거의 처리 완료, 모든 액터 로드 및 초기화 완료
- World 가 초기화 됨.
- LoadMap은 GameInstance 의 LocalPlayer를 찾아서 SpawnPlayActor → PC 생성
- 이제 플레이어가 게임에 참여하려면, 항상 로그인 프로세스를 거쳐야 함.
- UWorld::InitializeActorsForPlay
- PlayerController 생성
- GameMode의 Login 함수 호출하면 PlayerController 만들어 반환
- PlayerController 의 PostinitializeComponents 호출
- PlayerState 생성
- PlayerController가 생성
- PlayerState 는 모든 플레이어가 알아야 하는 데이터
- GameMode::Login 함수가 끝나면, PC 와 Player 객체 연결
- PlayerController::OnPossesss
- Character::PossessBy
- GameMode::PostLogin
- 새로운 플레이어가 참가했을 때 발생하는 모든 처리를 여기서 하게 됨.
- GameMode는 새로운 PlayerController에 대한 Pawn을 생성
- 추가로 새로 들어온 플레이어는 HandleStartingNewPlayer 함수에서 처리
- 부활한 플레이어를 처리하는 것은 RestartPlayer 함수에서 처리
- UWorld::BeginPlay
- GameMode::StartPlay
- GameMode::StartMatch
- GameState::HandleBeginPlay
- Actor::BeginPlay()
- UEngine::LoadMap 함수 종료
- FEngineLoop::Tick
- UGameEngine::Tick()
- UWorld::Tick()
주요 실행 로그
LogBS: ABSGameMode::ABSGameMode
LogBS: ABSGameMode::InitGame
LogBS: ABSGameStateBase::ABSGameStateBase
LogBS: ABSGameStateBase::PreInitializeComponents
LogBS: ABSGameStateBase::PostInitializeComponents
LogBS: ABSGameMode::PreInitializeComponents
LogBS: ABSGameMode::PostInitializeComponents
LogBS: ABSPlayerController::ABSPlayerController
LogBS: ABSPlayerState::ABSPlayerState
LogBS: UBSAbilitySystemComponent::OnRegister
LogBS: ABSPlayerState::PostInitializeComponents
LogBS: UBSDefaultCharacterComponent::OnRegister
LogBS: ABSCharacter::PreInitializeComponents
LogBS: ABSPlayerController::OnPossess
LogBS: ABSCharacter::PossessedBy
LogBS: ABSGameMode::PostLogin
LogBS: UBSDefaultCharacterComponent::BeginPlay
LogBS: ABSCharacter::BeginPlay
LogBS: ABSGameMode::StartPlay