AGameModeBase::InitGameState
#include "GameFramework/GameModeBase.h"
Access: public
Specifiers: virtual
Description
Initializes the GameState actor with default settings. Called automatically during PreInitializeComponents() and again after Reset(). Override to push initial match configuration onto the GameState.
Caveats & Gotchas
- • The GameState exists when this is called, but no players have joined yet. Do not reference PlayerStates or PlayerControllers here — they do not exist at this point.
- • This is also invoked during Reset() between matches. If your initialization logic is not idempotent (e.g. it appends to an array rather than setting it), stale data will accumulate across match resets.
Signature
ENGINE_API virtual void InitGameState(); Return Type
void Example
Push initial match configuration to the GameState C++
void AMyGameMode::InitGameState()
{
Super::InitGameState();
if (AMyGameState* GS = GetGameState<AMyGameState>())
{
GS->MatchTimeLimit = MatchDurationSeconds;
GS->MaxScore = ScoreLimit;
}
} Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?