AGameModeBase::PreInitializeComponents
#include "GameFramework/GameModeBase.h"
Access: public
Specifiers: virtualoverride
Description
Called before the GameMode's components are initialized. The engine uses this override to spawn the GameState actor and call InitGameState(), making it the earliest point where the GameState is available.
Caveats & Gotchas
- • Always call Super::PreInitializeComponents() — skipping it prevents the GameState from being spawned, which will crash during level load when other systems try to access GameState.
- • InitGame() runs before PreInitializeComponents(), so the GameState does not yet exist when InitGame() executes. If you need to configure GameState, do so in InitGameState() or later.
Signature
ENGINE_API virtual void PreInitializeComponents() override; Return Type
void Example
Configure the GameState immediately after it is spawned C++
void AMyGameMode::PreInitializeComponents()
{
Super::PreInitializeComponents(); // GameState spawned here
if (AMyGameState* GS = GetGameState<AMyGameState>())
{
GS->SetInitialScore(StartingScore);
}
} Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?