Game Initialization
The GameMode initializes when a World is loaded. The World Settings defines the GameMode to use and (in Lyra) which Lyra Experience to load by default.
There are different ways a World can come to be loaded, including clicking the “Play In Editor” (PIE) button.
As discussed in more detail in
Lyra Experience,
unlike other Games, in Lyra you must ensure to
delay all game play until
OnExperienceLoaded
, perhaps long after BeginPlay
.
World Load Procedure
World Loading follows this procedure:
- Initialize Components of all World Actors
- Init Game Mode
- Initialize Components (random Actor order)
- Player Login
- Create Player Controller & Player State
- World Begin Play
- Begin Play on all World Actors (random Actor order)
- Load Lyra Experience
OnExperienceLoaded
signals that game play can begin
Initialize Components of all World Actors
This is implemented by World🡒InitializeActorsForPlay
Init Game Mode
- GameMode🡒InitGame
Initialize Components
Initialization of World Actors is in RANDOM ORDER.
When the GameMode is initialized, it does:
- GameMode🡒PreInitializeComponents
- GameState🡒PreInitializeComponents
- GameState🡒PostInitializeComponents
- GameMode🡒InitGameState
- GameMode🡒PostInitializeComponents
Player Login
- GameMode🡒Login
- GameMode🡒SpawnPlayerController
- PlayerController🡒PreInitializeComponents
- PlayerController🡒PostInitializeComponents
- PlayerController🡒InitPlayerState
- PlayerState🡒PreInitializeComponents
- PlayerState🡒PostInitializeComponents
- GameState🡒AddPlayerState
- PlayerController->OnPlayerStateChanged
- PlayerController🡒AddCheats
- PlayerController🡒InitPlayerState
- GameMode🡒InitNewPlayer
- GameMode🡒SpawnPlayerController
- PlayerController🡒SetPlayer
- PlayerController🡒SetupInputComponent
- PlayerController🡒ReceivedPlayer
CommonGame
adds root HUD layout
- GameMode🡒OnPostLogin
World BeginPlay
- All World Subsystems
OnWorldBeginPlay
- GameMode🡒StartPlay
- GameState🡒HandleBeginPlay
- PlayerController🡒PushInputComponent
- All World Actors BeginPlay (RANDOM ORDER)
- GameMode🡒BeginPlay
- GameState🡒BeginPlay
- PlayerController🡒BeginPlay
- PlayerState🡒BeginPlay
- … etc …
- GameState🡒HandleBeginPlay
Load Lyra Experience
In PIE, the World’s Default Lyra Experience gets loaded on the tick after GameMode🡒InitGame.
In Game, the appropriate Lyra Experience is loaded by the Frontend State Component (or your similar Game State Component).
Experience Load Procedure
- Load Experience Asset and its References
- Load all GameFeature Plugin (GFP) dependencies
- Activate GFPs (execute GameFeature Actions)
- Broadcast
OnExperienceLoaded
For full details, see Experience Loading Procedure