AGameModeBase

The GameModeBase defines the game being played.

Windows
MacOS
Linux

Inheritance Hierarchy

References

Module

Engine

Header

/Engine/Source/Runtime/Engine/Classes/GameFramework/GameModeBase.h

Include

#include "GameFramework/GameModeBase.h"

Syntax

class AGameModeBase : public AInfo

Remarks

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.

Variables

Name Description

Protected variable

uint32: 1

 

bPauseable

Whether the game is pauseable.

Protected variable

uint32: 1

 

bStartPlayersAsSpectators

Whether players should immediately spawn when logging in, or stay as spectators until they manually spawn

Public variable

uint32: 1

 

bUseSeamlessTravel

Whether the game perform map travels using SeamlessTravel() which loads in the background and doesn't disconnect clients

Public variable

TSubclassOf< AP...

 

DefaultPawnClass

The default pawn class used by players.

Public variable

FText

 

DefaultPlayerName

The default player name assigned to players that join with no name specified.

Public variable

AGameSession &#...

 

GameSession

Game Session handles login approval, arbitration, online game interface

Public variable

TSubclassOf< AG...

 

GameSessionClass

Class of GameSession, which handles login approval and online game interface

Public variable

AGameStateBase ...

 

GameState

GameState is used to replicate game state relevant properties to all clients.

Public variable

TSubclassOf< AG...

 

GameStateClass

Class of GameState associated with this GameMode.

Public variable

TSubclassOf< AH...

 

HUDClass

HUD class this game uses.

Public variable

FString

 

OptionsString

Save options string and parse it when needed

Protected variable

TArray< FCanUnp...

 

Pausers

The list of delegates to check before unpausing a game

Public variable

TSubclassOf< AP...

 

PlayerControllerClass

The class of PlayerController to spawn for players logging in.

Public variable

TSubclassOf< AP...

 

PlayerStateClass

A PlayerState of this class will be associated with every player to replicate relevant player information to all clients.

Public variable

TSubclassOf< AP...

 

ReplaySpectatorPlayerControllerClass

The PlayerController class used when spectating a network replay.

Public variable

AServerStatRepl...

 

ServerStatReplicator

Public variable

TSubclassOf< AS...

 

ServerStatReplicatorClass

Public variable

TSubclassOf< AS...

 

SpectatorClass

The pawn class used by the PlayerController for players when spectating.

Constructors

Name Description

Public function

AGameModeBase

(
    const FObjectInitializer& ObjectIn...
)

Functions

Name Description

Public function Virtual

bool

 

AllowCheats

(
    APlayerController* P
)

Public function Virtual

bool

 

AllowPausing

(
    APlayerController* PC
)

Returns true if the player is allowed to pause the game

Public function Virtual

bool

 

CanServerTravel

(
    const FString& URL,
    bool bAbsolute
)

Returns true if allowed to server travel

Public function

bool

 

CanSpectate

(
    APlayerController* Viewer,
    APlayerState* ViewTarget
)

Return whether Viewer is allowed to spectate from the point of view of ViewTarget.

Public function Virtual

void

 

ChangeName

(
    AController* Controller,
    const FString& NewName,
    bool bNameChange
)

Sets the name for a controller

Public function

AActor *

 

ChoosePlayerStart

(
    AController* Player
)

Return the 'best' player start for this player to spawn from Default implementation looks for a random unoccupied spot

Public function Virtual

bool

 

ClearPause()

Checks the list of delegates to determine if the pausing can be cleared.

Public function

AActor *

 

FindPlayerStart

(
    AController* Player,
    const FString& IncomingName
)

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

Protected function Virtual

void

 

FinishRestartPlayer

(
    AController* NewPlayer,
    const FRotator& StartRotation
)

Handles second half of RestartPlayer

Public function

void

 

ForceClearUnpauseDelegates

(
    AActor* PauseActor
)

Forcibly removes an object's CanUnpause delegates from the list of pausers.

Public function Virtual

void

 

GameWelcomePlayer

(
    UNetConnection* Connection,
    FString& RedirectURL
)

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

Protected function Virtual

void

 

GenericPlayerInitialization

(
    AController* C
)

Handles all player initialization that is shared between the travel methods (i.e. called from both PostLogin() and HandleSeamlessTravelPlayer())

Public function

UClass *

 

GetDefaultPawnClassForController

(
    AController* InController
)

Returns default pawn class for given controller

Public function Virtual Const

TSubclassOf<...

 

GetGameSessionClass()

Return GameSession class to use for this game

Public function Const

T *

 

GetGameState()

Helper template to returns the current GameState casted to the desired type.

Public function Virtual

int32

 

GetNumPlayers()

Returns number of active human players, excluding spectators

Public function Virtual

int32

 

GetNumSpectators()

Returns number of human players currently spectating

Public function Virtual

TSubclassOf<...

 

GetPlayerControllerClassToSpawnForSeamlessTravel

(
    APlayerController* PreviousPla...
)

Gets the class that should be used for spawning a player controller during seamless travel

Public function Virtual

void

 

GetSeamlessTravelActorList

(
    bool bToTransition,
    TArray< AActor* >& ActorList
)

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)

Public function 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

Public function

void

 

HandleStartingNewPlayer

(
    APlayerController* NewPlayer
)

Signals that a player is ready to enter the game, which may start it up

Public function Virtual Const

bool

 

HasMatchStarted()

Returns true if the match start callbacks have been called

Public function Virtual

void

 

InitGame

(
    const FString& MapName,
    const FString& Options,
    FString& ErrorMessage
)

Initialize the game.

Public function 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()

Protected function

void

 

InitializeHUDForPlayer

(
    APlayerController* NewPlayer
)

Initialize the AHUD object for a player.

Protected function Virtual

FString

 

InitNewPlayer

(
    APlayerController* NewPlayerCo...,
    const FUniqueNetIdRepl& UniqueId,
    const FString& Options,
    const FString& Portal
)

Customize incoming player based on URL options

Protected function Virtual

void

 

InitSeamlessTravelPlayer

(
    AController* NewController
)

Handles initializing a seamless travel player, handles logic similar to InitNewPlayer

Public function

void

 

InitStartSpot

(
    AActor* StartSpot,
    AController* NewPlayer
)

Called from RestartPlayerAtPlayerStart, can be used to initialize the start spawn actor

Public function Virtual

bool

 

IsHandlingReplays()

Returns true if replays will start/stop during gameplay starting/stopping

Public function Virtual Const

bool

 

IsPaused()

Returns true if the game is paused

Public function

AActor *

 

K2_FindPlayerStart

(
    AController* Player,
    const FString& IncomingName
)

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

Public function

void

 

K2_OnChangeName

(
    AController* Other,
    const FString& NewName,
    bool bNameChange
)

Overridable event for GameMode blueprint to respond to a change name call

Public function

void

 

K2_OnLogout

(
    AController* ExitingController
)

Implementable event when a Controller with a PlayerState leaves the game.

Public function

void

 

K2_OnRestartPlayer

(
    AController* NewPlayer
)

Implementable event called at the end of RestartPlayer

Protected function

void

 

K2_OnSwapPlayerControllers

(
    APlayerController* OldPC,
    APlayerController* NewPC
)

Called when a PlayerController is swapped to a new one during seamless travel

Public function

void

 

K2_PostLogin

(
    APlayerController* NewPlayer
)

Notification that a player has successfully logged in, and has been given a player controller

Public function Virtual

APlayerContr...

 

Login

(
    UPlayer* NewPlayer,
    ENetRole InRemoteRole,
    const FString& Portal,
    const FString& Options,
    const FUniqueNetIdRepl& UniqueId,
    FString& ErrorMessage
)

Called to login new players by creating a player controller, overridable by the game

Public function Virtual

void

 

Logout

(
    AController* Exiting
)

Called when a Controller with a PlayerState leaves the game or is destroyed

Public function Const

bool

 

MustSpectate

(
    APlayerController* NewPlayerCo...
)

Returns true if NewPlayerController may only join the server as a spectator.

Public function

bool

 

PlayerCanRestart

(
    APlayerController* Player
)

Returns true if it's valid to call RestartPlayer. By default will call Player->CanRestartPlayer

Public function Virtual

void

 

PostLogin

(
    APlayerController* NewPlayer
)

Called after a successful login.

Public function Virtual

void

 

PostSeamlessTravel()

Called after a seamless level transition has been completed on the new GameMode.

Public function Virtual

void

 

PreLogin

(
    const FString& Options,
    const FString& Address,
    const FUniqueNetIdRepl& UniqueId,
    FString& ErrorMessage
)

Accept or reject a player attempting to join the server.

Protected function Virtual

APlayerContr...

 

ProcessClientTravel

(
    FString& URL,
    FGuid NextMapGuid,
    bool bSeamless,
    bool bAbsolute
)

Notifies all clients to travel to the specified URL.

Public function Virtual

void

 

ProcessServerTravel

(
    const FString& URL,
    bool bAbsolute
)

Handles request for server to travel to a new URL, with all players

Protected function Virtual

void

 

ReplicateStreamingStatus

(
    APlayerController* PC
)

Replicates the current level streaming status to the given PlayerController

Public function Virtual

void

 

ResetLevel()

Overridable function called when resetting level.

Public function Virtual

void

 

RestartPlayer

(
    AController* NewPlayer
)

Tries to spawn the player's pawn, at the location returned by FindPlayerStart

Public function Virtual

void

 

RestartPlayerAtPlayerStart

(
    AController* NewPlayer,
    AActor* StartSpot
)

Tries to spawn the player's pawn at the specified actor's location

Public function Virtual

void

 

RestartPlayerAtTransform

(
    AController* NewPlayer,
    const FTransform& SpawnTransform
)

Tries to spawn the player's pawn at a specific location

Public function Virtual

void

 

ReturnToMainMenuHost()

Return to main menu, and disconnect any players

Public function Virtual

bool

 

SetPause

(
    APlayerController* PC,
    FCanUnpause CanUnpauseDelegate
)

Adds the delegate to the list if the player Controller has the right to pause the game.

Public function Virtual

void

 

SetPlayerDefaults

(
    APawn* PlayerPawn
)

Initializes player pawn back to starting values, called from RestartPlayer

Public function

bool

 

ShouldReset

(
    AActor* ActorToReset
)

Overridable function to determine whether an Actor should have Reset called when the game has Reset called on it.

Protected function Virtual

bool

 

ShouldSpawnAtStartSpot

(
    AController* Player
)

Return true if FindPlayerStart should use the StartSpot stored on Player instead of calling ChoosePlayerStart

Protected function Virtual

bool

 

ShouldStartInCinematicMode

(
    APlayerController* Player,
    bool& OutHidePlayer,
    bool& OutHideHud,
    bool& OutDisableMovement,
    bool& OutDisableTurning
)

Check to see if we should start in cinematic mode (e.g. matinee movie capture).

Public function

APawn *

 

SpawnDefaultPawnAtTransform

(
    AController* NewPlayer,
    const FTransform& SpawnTransform
)

Called during RestartPlayer to actually spawn the player's pawn, when using a transform

Public function

APawn *

 

SpawnDefaultPawnFor

(
    AController* NewPlayer,
    AActor* StartSpot
)

Called during RestartPlayer to actually spawn the player's pawn, when using a start spot

Public function Virtual

APlayerContr...

 

SpawnPlayerController

(
    ENetRole InRemoteRole,
    const FString& Options
)

Spawns the appropriate PlayerController for the given options; split out from Login() for easier overriding.

Protected function Virtual

APlayerContr...

 

SpawnPlayerControllerCommon

(
    ENetRole InRemoteRole,
    FVector const& SpawnLocation,
    FRotator const& SpawnRotation,
    TSubclassOf< APlayerController > In...
)

Does the work of spawning a player controller of the given class at the given transform.

Public function Virtual

bool

 

SpawnPlayerFromSimulate

(
    const FVector& NewLocation,
    const FRotator& NewRotation
)

Used in the editor to spawn a PIE player after the game has already started

Public function Virtual

void

 

StartPlay()

Transitions to calls BeginPlay on actors.

Public function Virtual

void

 

StartToLeaveMap()

Start the transition out of the current map.

Public function Virtual

void

 

SwapPlayerControllers

(
    APlayerController* OldPC,
    APlayerController* NewPC
)

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

Protected function 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.

Overridden from AActor

Name Description

Public function Virtual

void

 

PreInitializeComponents()

Called right before components are initialized, only called during gameplay

Public function Virtual

void

 

Reset()

Reset actor to initial state - used when restarting level without reloading.

Deprecated Functions

Name Description

Public function Virtual

APlayerContr...

 

SpawnPlayerController

(
    ENetRole InRemoteRole,
    FVector const& SpawnLocation,
    FRotator const& SpawnRotation
)

SpawnPlayerController with Location and Rotation is deprecated, call or override the version that takes an Option string instead

Public function Virtual

APlayerContr...

 

SpawnReplayPlayerController

(
    ENetRole InRemoteRole,
    FVector const& SpawnLocation,
    FRotator const& SpawnRotation
)

SpawnReplayPlayerController is deprecated, replay controller spawning is handled inside the new version of the SpawnPlayerController function

See Also

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss