RealDocs

AGameModeBase::InitGame

function Engine Since 4.14
#include "GameFramework/GameModeBase.h"
Access: public Specifiers: virtual

Description

Called before any actor's `PreInitializeComponents` — the very first GameMode event when a level loads. Use it to parse URL options and set up any data that must exist before players join or actors initialize.

Signature

virtual void InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)

Parameters

Name Type Description Default
MapName const FString& The name of the map being loaded.
Options const FString& URL option string (e.g. "?Rounds=5").
ErrorMessage FString& Set to a non-empty string to abort level loading.

Return Type

void

Caveats & Gotchas

  • No actors have had `BeginPlay` called at this point — avoid accessing dynamic gameplay objects.
  • Setting `ErrorMessage` to a non-empty string aborts level loading; use sparingly.
  • Always call `Super::InitGame()` first.

Example

Parse URL options on startup C++
void AMyGameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
{
    Super::InitGame(MapName, Options, ErrorMessage);
    FString RoundCount = UGameplayStatics::ParseOption(Options, TEXT("Rounds"));
    MaxRounds = RoundCount.IsEmpty() ? 3 : FCString::Atoi(*RoundCount);
}

Version History

Introduced in: 4.14

Version Status Notes
5.6 stable
5.0 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.