Skip to content

Instantly share code, notes, and snippets.

@gamerxl
Last active January 15, 2023 17:28
Show Gist options
  • Save gamerxl/1b8e7dea36f6d876c09b13b0866897d7 to your computer and use it in GitHub Desktop.
Save gamerxl/1b8e7dea36f6d876c09b13b0866897d7 to your computer and use it in GitHub Desktop.
Travel to server default map during game init (GameInstance) from c++ in unreal engine. You can get or set the server default map below "Maps & Modes" in Project Settings.
// Example how to travel to server default map during game init.
// Use a custom game instance and override method Init from UGameInstance.
void UCustomGameInstance::Init()
{
Super::Init();
if (IsDedicatedServerInstance())
{
FString ServerDefaultMap;
GConfig->GetString(
TEXT("/Script/EngineSettings.GameMapsSettings"),
TEXT("ServerDefaultMap"),
ServerDefaultMap,
GEngineIni);
FString URL = ServerDefaultMap.Append("?listen");
UE_LOG(LogTemp, Warning, TEXT("UDefaultGameInstance::Init: Travel to %s"), *URL);
GetWorld()->ServerTravel(URL, true, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment