GlobalDefaultGameMode

GlobalDefaultGameMode

#Overview

name: GlobalDefaultGameMode

The value of this variable can be defined or overridden in .ini config files. 2 .ini config files referencing this setting variable.

It is referenced in 5 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of GlobalDefaultGameMode is to specify the default GameMode class to be used in the game when no other GameMode is specified through other means (such as per-map DefaultGameMode or URL parameters). This setting variable is a crucial part of Unreal Engine’s game framework system.

GlobalDefaultGameMode is primarily used by the Engine’s core systems, particularly the game framework and map loading subsystems. It’s referenced in the CookOnTheFlyServer, which suggests it’s also important for the cooking process when packaging games.

The value of this variable is set in the Game Maps Settings, which is part of the Engine Settings module. It can be set through the project settings in the Unreal Editor or programmatically using the SetGlobalDefaultGameMode function.

This variable interacts closely with GlobalDefaultServerGameMode, which is used specifically for dedicated servers. If GlobalDefaultServerGameMode is set and the game is running as a dedicated server, it will be used instead of GlobalDefaultGameMode.

Developers should be aware that this variable sets a fallback GameMode. It’s used when no other GameMode specification is found, ensuring that every map has a valid GameMode. However, it’s generally better to specify GameModes on a per-map basis for more fine-grained control.

Best practices when using this variable include:

  1. Set it to a reasonable default that works for most of your game’s maps.
  2. Use per-map GameMode settings for maps that need different rules.
  3. Consider setting GlobalDefaultServerGameMode if your game has dedicated servers with different rules.
  4. Be cautious when changing this value at runtime, as it could affect the behavior of subsequently loaded maps.
  5. Ensure the specified GameMode class exists and is properly set up to avoid runtime errors.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/BaseEngine.ini:14, section: [/Script/EngineSettings.GameMapsSettings]

Location: <Workspace>/Projects/Lyra/Config/DefaultEngine.ini:66, section: [/Script/EngineSettings.GameMapsSettings]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Editor/UnrealEd/Private/CookOnTheFlyServer.cpp:9334

Scope (from outer to inner):

file
function     void UCookOnTheFlyServer::GetGameDefaultObjects

Source code excerpt:

		AddDefaultObject(FName(TEXT("GameDefaultMap")));
		AddDefaultObject(FName(TEXT("ServerDefaultMap")));
		AddDefaultObject(FName(TEXT("GlobalDefaultGameMode")));
		AddDefaultObject(FName(TEXT("GlobalDefaultServerGameMode")));
		AddDefaultObject(FName(TEXT("GameInstanceClass")));
	}
}

bool UCookOnTheFlyServer::IsCookByTheBookRunning() const

#Loc: <Workspace>/Engine/Source/Runtime/EngineSettings/Classes/GameMapsSettings.h:135

Scope (from outer to inner):

file
class        class UGameMapsSettings : public UObject

Source code excerpt:


	/**
	 * Set the default game type (see GlobalDefaultGameMode below)
	 *
	 * @param NewGameMode name of valid map to use
	 */
	static ENGINESETTINGS_API void SetGlobalDefaultGameMode( const FString& NewGameMode );

	ENGINESETTINGS_API virtual void PostInitProperties() override;
	ENGINESETTINGS_API virtual void PostReloadConfig( class FProperty* PropertyThatWasLoaded ) override;

public:

#Loc: <Workspace>/Engine/Source/Runtime/EngineSettings/Classes/GameMapsSettings.h:203

Scope (from outer to inner):

file
class        class UGameMapsSettings : public UObject

Source code excerpt:

	/** GameMode to use if not specified in any other way. (e.g. per-map DefaultGameMode or on the URL). */
	UPROPERTY(config, noclear, EditAnywhere, Category=DefaultModes, meta=(MetaClass="/Script/Engine.GameModeBase", DisplayName="Default GameMode"))
	FSoftClassPath GlobalDefaultGameMode;

	/**
	 * GameMode to use if not specified in any other way. (e.g. per-map DefaultGameMode or on the URL) (DEDICATED SERVERS)
	 * If not set, the GlobalDefaultGameMode value will be used.
	 */
	UPROPERTY(config, EditAnywhere, Category=DefaultModes, meta=(MetaClass="/Script/Engine.GameModeBase"), AdvancedDisplay)
	FSoftClassPath GlobalDefaultServerGameMode;

	/** Overrides the GameMode to use when loading a map that starts with a specific prefix */
	UPROPERTY(config, EditAnywhere, Category = DefaultModes, AdvancedDisplay)
	TArray<FGameModeName> GameModeMapPrefixes;

	/** List of GameModes to load when game= is specified in the URL (e.g. "DM" could be an alias for "MyProject.MyGameModeMP_DM") */

#Loc: <Workspace>/Engine/Source/Runtime/EngineSettings/Private/EngineSettingsModule.cpp:100

Scope (from outer to inner):

file
function     FString UGameMapsSettings::GetGlobalDefaultGameMode

Source code excerpt:

	return IsRunningDedicatedServer() && GameMapsSettings->GlobalDefaultServerGameMode.IsValid()
		? GameMapsSettings->GlobalDefaultServerGameMode.ToString()
		: GameMapsSettings->GlobalDefaultGameMode.ToString();
}

FString UGameMapsSettings::GetGameModeForName(const FString& GameModeName)
{
	UGameMapsSettings* GameMapsSettings = Cast<UGameMapsSettings>(UGameMapsSettings::StaticClass()->GetDefaultObject());

#Loc: <Workspace>/Engine/Source/Runtime/EngineSettings/Private/EngineSettingsModule.cpp:208

Scope (from outer to inner):

file
function     void UGameMapsSettings::SetGlobalDefaultGameMode

Source code excerpt:

	UGameMapsSettings* GameMapsSettings = Cast<UGameMapsSettings>(UGameMapsSettings::StaticClass()->GetDefaultObject());
	
	GameMapsSettings->GlobalDefaultGameMode = NewGameMode;
}

UGameMapsSettings* UGameMapsSettings::GetGameMapsSettings()
{
	return GetMutableDefault<UGameMapsSettings>();
}