Navigation
API > API/Runtime > API/Runtime/Engine
The GameModeBase defines the game being played. It governs the game rules, scoring, what actors are allowed to exist in this game type, and who may enter the game.
It is only instanced on the server and will never exist on the client.
A GameModeBase actor is instantiated when the level is initialized for gameplay in C++ UGameEngine::LoadMap().
The class of this GameMode actor is determined by (in order) either the URL ?game=xxx, the GameMode Override value set in the World Settings, or the DefaultGameMode entry set in the game's Project Settings.
| Name | AGameModeBase |
| Type | class |
| Header File | /Engine/Source/Runtime/Engine/Classes/GameFramework/GameModeBase.h |
| Include Path | #include "GameFramework/GameModeBase.h" |
Syntax
UCLASS (Config=Game, NotPlaceable, BlueprintType, Blueprintable, Transient,
HideCategories=(Info, Rendering, MovementReplication, Replication, Actor),
Meta=(ShortTooltip="Game Mode Base defines the game being played, its rules, scoring, and other facets of the game type."),
MinimalAPI)
class AGameModeBase : public AInfo
Inheritance Hierarchy
- UObjectBase → UObjectBaseUtility → UObject → AActor → AInfo → AGameModeBase
Derived Classes
AGameModeBase derived class hierarchy
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
AGameModeBase
(
const FObjectInitializer& ObjectInitializer |
GameFramework/GameModeBase.h |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| FOnPreLoginCompleteDelegate | TBaseDelegate_OneParam< void, const FString & > | GameFramework/GameModeBase.h |
Variables
Public
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| bUseSeamlessTravel | uint32 | Whether the game perform map travels using SeamlessTravel() which loads in the background and doesn't disconnect clients | GameFramework/GameModeBase.h |
|
| DefaultPawnClass | TSubclassOf< APawn > | The default pawn class used by players. | GameFramework/GameModeBase.h |
|
| DefaultPlayerName | FText | The default player name assigned to players that join with no name specified. | GameFramework/GameModeBase.h |
|
| GameSession | TObjectPtr< AGameSession > | Game Session handles login approval, arbitration, online game interface | GameFramework/GameModeBase.h |
|
| GameSessionClass | TSubclassOf< AGameSession > | Class of GameSession, which handles login approval and online game interface | GameFramework/GameModeBase.h |
|
| GameState | TObjectPtr< AGameStateBase > | GameState is used to replicate game state relevant properties to all clients. | GameFramework/GameModeBase.h |
|
| GameStateClass | TSubclassOf< AGameStateBase > | Class of GameState associated with this GameMode. | GameFramework/GameModeBase.h |
|
| HUDClass | TSubclassOf< AHUD > | HUD class this game uses. | GameFramework/GameModeBase.h |
|
| OptionsString | FString | Save options string and parse it when needed | GameFramework/GameModeBase.h |
|
| PlayerControllerClass | TSubclassOf< APlayerController > | The class of PlayerController to spawn for players logging in. | GameFramework/GameModeBase.h |
|
| PlayerStateClass | TSubclassOf< APlayerState > | A PlayerState of this class will be associated with every player to replicate relevant player information to all clients. | GameFramework/GameModeBase.h |
|
| ReplaySpectatorPlayerControllerClass | TSubclassOf< APlayerController > | The PlayerController class used when spectating a network replay. | GameFramework/GameModeBase.h |
|
| ServerStatReplicator | TObjectPtr< AServerStatReplicator > | GameFramework/GameModeBase.h |
|
|
| ServerStatReplicatorClass | TSubclassOf< AServerStatReplicator > | GameFramework/GameModeBase.h |
|
|
| SpectatorClass | TSubclassOf< ASpectatorPawn > | The pawn class used by the PlayerController for players when spectating. | GameFramework/GameModeBase.h |
|
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual bool AllowCheats
(
APlayerController* P |
Return true if player should be allowed to use cheats by default | GameFramework/GameModeBase.h | |
virtual bool AllowPausing
(
APlayerController* PC |
Returns true if the player is allowed to pause the game | GameFramework/GameModeBase.h | |
virtual bool CanServerTravel
(
const FString& URL, |
Returns true if allowed to server travel | GameFramework/GameModeBase.h | |
bool CanSpectate
(
APlayerController* Viewer, |
Return whether Viewer is allowed to spectate from the point of view of ViewTarget. | GameFramework/GameModeBase.h |
|
virtual void ChangeName
(
AController* Controller, |
Sets the name for a controller | GameFramework/GameModeBase.h |
|
AActor * ChoosePlayerStart
(
AController* Player |
Return the 'best' player start for this player to spawn from Default implementation looks for a random unoccupied spot | GameFramework/GameModeBase.h |
|
virtual bool ClearPause () |
Checks the list of delegates to determine if the pausing can be cleared. | GameFramework/GameModeBase.h | |
void DispatchPostLogin
(
AController* NewPlayer |
Called as part of the PostLogin process. This is the last step before we spawn a new player. | GameFramework/GameModeBase.h | |
AActor * FindPlayerStart
(
AController* Player, |
Return the specific player start actor that should be used for the next spawn This will either use a previously saved startactor, or calls ChoosePlayerStart | GameFramework/GameModeBase.h |
|
void ForceClearUnpauseDelegates
(
AActor* PauseActor |
Forcibly removes an object's CanUnpause delegates from the list of pausers. | GameFramework/GameModeBase.h | |
virtual void GameWelcomePlayer
(
UNetConnection* Connection, |
Allows game to send network messages to provide more information to the client joining the game via NMT_GameSpecific (for example required DLC) the out string RedirectURL is built in and send automatically if only a simple URL is needed | GameFramework/GameModeBase.h | |
UClass * GetDefaultPawnClassForController
(
AController* InController |
Returns default pawn class for given controller | GameFramework/GameModeBase.h |
|
EReplicationSystem GetGameNetDriverReplicationSystem() |
Return if the game mode is requesting a specific replication system to be used for the GameNetDriver | GameFramework/GameModeBase.h | |
virtual TSubclassOf< AGameSession > GetGameSessionClass() |
Return GameSession class to use for this game | GameFramework/GameModeBase.h | |
T * GetGameState() |
Helper template to returns the current GameState casted to the desired type. | GameFramework/GameModeBase.h | |
virtual int32 GetNumPlayers() |
Returns number of active human players, excluding spectators | GameFramework/GameModeBase.h |
|
virtual int32 GetNumSpectators() |
Returns number of human players currently spectating | GameFramework/GameModeBase.h |
|
virtual TSubclassOf< APlayerController > GetPlayerControllerClassToSpawnForSeamlessTravel
(
APlayerController* PreviousPlayerController |
Gets the class that should be used for spawning a player controller during seamless travel | GameFramework/GameModeBase.h | |
virtual void GetSeamlessTravelActorList
(
bool bToTransition, |
Called on server during seamless level transitions to get the list of Actors that should be moved into the new level PlayerControllers, Role < ROLE_Authority Actors, and any non-Actors that are inside an Actor that is in the list (i.e. Object.Outer == Actor in the list) are all automatically moved regardless of whether they're included here only dynamic actors in the PersistentLevel may be moved (this includes all actors spawned during gameplay) this is called for both parts of the transition because actors might change while in the middle (e.g. players might join or leave the game) | GameFramework/GameModeBase.h | |
virtual void HandleSeamlessTravelPlayer
(
AController*& C |
Handles reinitializing players that remained through a seamless level transition called from C++ for players that finished loading after the server | GameFramework/GameModeBase.h | |
void HandleStartingNewPlayer
(
APlayerController* NewPlayer |
Signals that a player is ready to enter the game, which may start it up | GameFramework/GameModeBase.h |
|
virtual bool HasMatchEnded() |
Returns true if the match can be considered ended | GameFramework/GameModeBase.h |
|
virtual bool HasMatchStarted() |
Returns true if the match start callbacks have been called | GameFramework/GameModeBase.h |
|
| Initialize the game. | GameFramework/GameModeBase.h | ||
virtual void InitGameState() |
Initialize the GameState actor with default settings called during PreInitializeComponents() of the GameMode after a GameState has been spawned as well as during Reset() | GameFramework/GameModeBase.h | |
void InitStartSpot
(
AActor* StartSpot, |
Called from RestartPlayerAtPlayerStart, can be used to initialize the start spawn actor | GameFramework/GameModeBase.h |
|
virtual bool IsHandlingReplays() |
Returns true if replays will start/stop during gameplay starting/stopping | GameFramework/GameModeBase.h | |
virtual bool IsPaused() |
Returns true if the game is paused | GameFramework/GameModeBase.h | |
AActor * K2_FindPlayerStart
(
AController* Player, |
Return the specific player start actor that should be used for the next spawn This will either use a previously saved startactor, or calls ChoosePlayerStart | GameFramework/GameModeBase.h |
|
void K2_OnChangeName
(
AController* Other, |
Overridable event for GameMode blueprint to respond to a change name call | GameFramework/GameModeBase.h |
|
void K2_OnLogout
(
AController* ExitingController |
Implementable event when a Controller with a PlayerState leaves the game. | GameFramework/GameModeBase.h |
|
void K2_OnRestartPlayer
(
AController* NewPlayer |
Implementable event called at the end of RestartPlayer | GameFramework/GameModeBase.h |
|
void K2_PostLogin
(
APlayerController* NewPlayer |
Notification that a player has successfully logged in, and has been given a player controller | GameFramework/GameModeBase.h |
|
virtual APlayerController * Login
(
UPlayer* NewPlayer, |
Called to login new players by creating a player controller, overridable by the game | GameFramework/GameModeBase.h | |
virtual void Logout
(
AController* Exiting |
Called when a Controller with a PlayerState leaves the game or is destroyed | GameFramework/GameModeBase.h | |
bool MustSpectate
(
APlayerController* NewPlayerController |
Returns true if NewPlayerController may only join the server as a spectator. | GameFramework/GameModeBase.h |
|
bool PlayerCanRestart
(
APlayerController* Player |
Returns true if it's valid to call RestartPlayer. By default will call Player->CanRestartPlayer | GameFramework/GameModeBase.h |
|
virtual void PostLogin
(
APlayerController* NewPlayer |
Called after a successful login. | GameFramework/GameModeBase.h | |
virtual void PostSeamlessTravel () |
Called after a seamless level transition has been completed on the new GameMode. | GameFramework/GameModeBase.h | |
virtual void PreLogin
(
const FString& Options, |
Accept or reject a player attempting to join the server. | GameFramework/GameModeBase.h | |
virtual void PreLoginAsync
(
const FString& Options, |
Async version of PreLogin that MUST call OnComplete when done, otherwise incoming client connections will hang or timeout. | GameFramework/GameModeBase.h | |
virtual void ProcessServerTravel
(
const FString& URL, |
Handles request for server to travel to a new URL, with all players | GameFramework/GameModeBase.h | |
virtual void ResetLevel () |
Overridable function called when resetting level. | GameFramework/GameModeBase.h |
|
virtual void RestartPlayer
(
AController* NewPlayer |
Tries to spawn the player's pawn, at the location returned by FindPlayerStart | GameFramework/GameModeBase.h |
|
virtual void RestartPlayerAtPlayerStart
(
AController* NewPlayer, |
Tries to spawn the player's pawn at the specified actor's location | GameFramework/GameModeBase.h |
|
virtual void RestartPlayerAtTransform
(
AController* NewPlayer, |
Tries to spawn the player's pawn at a specific location | GameFramework/GameModeBase.h |
|
virtual void ReturnToMainMenuHost() |
Return to main menu, and disconnect any players | GameFramework/GameModeBase.h |
|
virtual bool SetPause
(
APlayerController* PC, |
Adds the delegate to the list if the player Controller has the right to pause the game. | GameFramework/GameModeBase.h | |
virtual void SetPlayerDefaults
(
APawn* PlayerPawn |
Initializes player pawn back to starting values, called from RestartPlayer | GameFramework/GameModeBase.h | |
bool ShouldReset
(
AActor* ActorToReset |
Overridable function to determine whether an Actor should have Reset called when the game has Reset called on it. | GameFramework/GameModeBase.h |
|
APawn * SpawnDefaultPawnAtTransform
(
AController* NewPlayer, |
Called during RestartPlayer to actually spawn the player's pawn, when using a transform | GameFramework/GameModeBase.h |
|
APawn * SpawnDefaultPawnFor
(
AController* NewPlayer, |
Called during RestartPlayer to actually spawn the player's pawn, when using a start spot | GameFramework/GameModeBase.h |
|
virtual APlayerController * SpawnPlayerController
(
ENetRole InRemoteRole, |
GameFramework/GameModeBase.h | ||
virtual APlayerController * SpawnPlayerController
(
ENetRole InRemoteRole, |
Spawns the appropriate PlayerController for the given options; split out from Login() for easier overriding. | GameFramework/GameModeBase.h | |
virtual bool SpawnPlayerFromSimulate
(
const FVector& NewLocation, |
Used in the editor to spawn a PIE player after the game has already started | GameFramework/GameModeBase.h | |
virtual APlayerController * SpawnReplayPlayerController
(
ENetRole InRemoteRole, |
GameFramework/GameModeBase.h | ||
virtual void StartPlay() |
Transitions to calls BeginPlay on actors. | GameFramework/GameModeBase.h |
|
virtual void StartToLeaveMap () |
Start the transition out of the current map. | GameFramework/GameModeBase.h | |
virtual void SwapPlayerControllers
(
APlayerController* OldPC, |
Used to swap a viewport/connection's PlayerControllers when seamless traveling and the new GameMode's controller class is different than the previous includes network handling | GameFramework/GameModeBase.h |
Overridden from AActor
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void PreInitializeComponents() |
Called right before components are initialized, only called during gameplay | GameFramework/GameModeBase.h | |
virtual void Reset() |
Reset actor to initial state - used when restarting level without reloading. | GameFramework/GameModeBase.h |
Protected
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void FailedToRestartPlayer
(
AController* NewPlayer |
Called in the event that we fail to spawn a controller's pawn, which maybe it didn't have one or maybe it tried to spawn and was destroyed due to collision. | GameFramework/GameModeBase.h | |
virtual void FinishRestartPlayer
(
AController* NewPlayer, |
Handles second half of RestartPlayer | GameFramework/GameModeBase.h | |
virtual void GenericPlayerInitialization
(
AController* C |
Handles all player initialization that is shared between the travel methods (i.e. called from both PostLogin() and HandleSeamlessTravelPlayer()) | GameFramework/GameModeBase.h | |
void InitializeHUDForPlayer
(
APlayerController* NewPlayer |
Initialize the AHUD object for a player. | GameFramework/GameModeBase.h |
|
virtual FString InitNewPlayer
(
APlayerController* NewPlayerController, |
Customize incoming player based on URL options | GameFramework/GameModeBase.h | |
virtual void InitSeamlessTravelPlayer
(
AController* NewController |
Handles initializing a seamless travel player, handles logic similar to InitNewPlayer | GameFramework/GameModeBase.h | |
void K2_OnSwapPlayerControllers
(
APlayerController* OldPC, |
Called when a PlayerController is swapped to a new one during seamless travel | GameFramework/GameModeBase.h |
|
virtual void OnPostLogin
(
AController* NewPlayer |
Called as part of the PostLogin process. This is the last step before we spawn a new player. | GameFramework/GameModeBase.h | |
virtual APlayerController * ProcessClientTravel
(
FString& URL, |
Notifies all clients to travel to the specified URL. | GameFramework/GameModeBase.h | |
virtual void ReplicateStreamingStatus
(
APlayerController* PC |
Replicates the current level streaming status to the given PlayerController | GameFramework/GameModeBase.h | |
virtual bool ShouldSpawnAtStartSpot
(
AController* Player |
Return true if FindPlayerStart should use the StartSpot stored on Player instead of calling ChoosePlayerStart | GameFramework/GameModeBase.h | |
virtual bool ShouldStartInCinematicMode
(
APlayerController* Player, |
Check to see if we should start in cinematic mode | GameFramework/GameModeBase.h | |
virtual APlayerController * SpawnPlayerControllerCommon
(
ENetRole InRemoteRole, |
Does the work of spawning a player controller of the given class at the given transform. | GameFramework/GameModeBase.h | |
virtual void UpdateGameplayMuteList
(
APlayerController* aPlayer |
Used to notify the game type that it is ok to update a player's gameplay specific muting information now. | GameFramework/GameModeBase.h | |
virtual bool UpdatePlayerStartSpot
(
AController* Player, |
Attempts to initialize the 'StartSpot' of the Player. | GameFramework/GameModeBase.h |