AGameMode

GameMode is a subclass of GameModeBase that behaves like a multiplayer match-based game.

Windows
MacOS
Linux

Inheritance Hierarchy

References

Module

Engine

Header

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

Include

#include "GameFramework/GameMode.h"

Syntax

class AGameMode : public AGameModeBase

Remarks

GameMode is a subclass of GameModeBase that behaves like a multiplayer match-based game. It has default behavior for picking spawn points and match state. If you want a simpler base, inherit from GameModeBase instead.

Variables

Name Description

Public variable

uint32: 1

 

bDelayedStart

Whether the game should immediately start when the first player logs in.

Protected variable

bool

 

bHandleDedicatedServerReplays

If true, dedicated servers will record replays when HandleMatchHasStarted/HandleMatchHasStopped is called

Public variable

TSubclassOf< cl...

 

EngineMessageClass

Contains strings describing localized game agnostic messages.

Public variable

TArray< class A...

 

InactivePlayerArray

PlayerStates of players who have disconnected from the server (saved in case they reconnect)

Protected variable

float

 

InactivePlayerStateLifeSpan

Time a playerstate will stick around in an inactive state after a player logout

Protected variable

FName

 

MatchState

What match state we are currently in

Protected variable

int32

 

MaxInactivePlayers

The maximum number of inactive players before we kick the oldest ones out

Public variable

float

 

MinRespawnDelay

Minimum time before player can respawn after dying.

Public variable

int32

 

NumBots

Number of non-human players (AI controlled but participating as a player).

Public variable

int32

 

NumPlayers

Current number of human players.

Public variable

int32

 

NumSpectators

Current number of spectators.

Public variable

int32

 

NumTravellingPlayers

Number of players that are still traveling from a previous map

Constructors

Name Description

Public function

AGameMode

(
    const FObjectInitializer& ObjectIn...
)

Functions

Name Description

Public function Virtual

void

 

AbortMatch()

Report that a match has failed due to unrecoverable error

Public function Virtual

void

 

AddInactivePlayer

(
    APlayerState* PlayerState,
    APlayerController* PC
)

Add PlayerState to the inactive list, remove from the active list

Public function Virtual

void

 

Broadcast

(
    AActor* Sender,
    const FString& Msg,
    FName Type
)

Broadcast a string to all players.

Public function Virtual

void

 

BroadcastLocalized

(
    AActor* Sender,
    TSubclassOf< ULocalMessage > Messag...,
    int32 Switch,
    APlayerState* RelatedPlayerSta...,
    APlayerState* RelatedPlayerSta...,
    UObject* OptionalObject
)

Broadcast a localized message to all players.

Public function Virtual

void

 

EndMatch()

Transition from InProgress to WaitingPostMatch.

Public function Virtual

bool

 

FindInactivePlayer

(
    APlayerController* PC
)

Attempt to find and associate an inactive PlayerState with entering PC.

Public function Const

FName

 

GetMatchState()

Returns the current match state, this is an accessor to protect the state machine flow

Public function Virtual

FString

 

GetNetworkNumber()

Get local address

Public function Virtual

bool

 

GetTravelType()

Return true if we want to travel_absolute, used by RestartGame by default

Public function Virtual

void

 

HandleDisconnect

(
    UWorld* InWorld,
    UNetDriver* NetDriver
)

Handles when a player is disconnected, before the session does

Protected function Virtual

void

 

HandleLeavingMap()

Called when the match transitions to LeavingMap

Protected function Virtual

void

 

HandleMatchAborted()

Called when the match transitions to Aborted

Protected function Virtual

void

 

HandleMatchHasEnded()

Called when the map transitions to WaitingPostMatch

Protected function Virtual

void

 

HandleMatchHasStarted()

Called when the state transitions to InProgress

Protected function Virtual

void

 

HandleMatchIsWaitingToStart()

Called when the state transitions to WaitingToStart

Public function Virtual

void

 

HandleStartingNewPlayer_Implementation

(
    APlayerController* NewPlayer
)

Public function Virtual Const

bool

 

IsMatchInProgress()

Returns true if the match state is InProgress or other gameplay state

Protected function

void

 

K2_OnSetMatchState

(
    FName NewState
)

Implementable event to respond to match state changes

Public function Virtual

void

 

MatineeCancelled()

Called when this PC is in cinematic mode, and its matinee is canceled by the user.

Public function Virtual

void

 

NotifyPendingConnectionLost

(
    const FUniqueNetIdRepl& Connection...
)

Called when a connection closes before getting to PostLogin()

Protected function Virtual

void

 

OnMatchStateSet()

Overridable virtual function to dispatch the appropriate transition functions before GameState and Blueprints get SetMatchState calls.

Public function Virtual

void

 

OverridePlayerState

(
    APlayerController* PC,
    APlayerState* OldPlayerState
)

Override PC's PlayerState with the values in OldPlayerState as part of the inactive player handling

Public function Virtual

bool

 

PlayerCanRestart_Implementation

(
    APlayerController* Player
)

Public function

void

 

PlayerSwitchedToSpectatorOnly

(
    APlayerController* PC
)

Will remove the controller from the correct count then add them to the spectator count.

Public function Virtual

void

 

PostCommitMapChange()

Called from CommitMapChange after unloading previous level and loading new level+sublevels.

Public function Virtual

void

 

PreCommitMapChange

(
    const FString& PreviousMapName,
    const FString& NextMapName
)

Called from CommitMapChange before unloading previous level. Used for asynchronous level streaming

Protected function

bool

 

ReadyToEndMatch()

Returns true if ready to End Match. Games should override this

Protected function

bool

 

ReadyToStartMatch()

Returns true if ready to Start Match. Games should override this

Public function

void

 

RemovePlayerControllerFromPlayerCount

(
    APlayerController* PC
)

Removes the passed in player controller from the correct count for player/spectator/tranistioning

Public function Virtual

void

 

RestartGame()

Restart the game, by default travel to the current map

Public function Virtual

void

 

Say

(
    const FString& Msg
)

Exec command to broadcast a string to all players

Protected function Virtual

void

 

SetMatchState

(
    FName NewState
)

Updates the match state and calls the appropriate transition functions

Public function Virtual

void

 

SetSeamlessTravelViewTarget

(
    APlayerController* PC
)

SetViewTarget of player control on server change

Public function Virtual

void

 

StartMatch()

Transition from WaitingToStart to InProgress.

Overridden from AGameModeBase

Name Description

Public function Virtual

bool

 

CanServerTravel

(
    const FString& URL,
    bool bAbsolute
)

Returns true if allowed to server travel

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

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 Virtual Const

bool

 

HasMatchEnded()

Returns true if the match state is WaitingPostMatch or later

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

 

InitSeamlessTravelPlayer

(
    AController* NewController
)

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

Public function Virtual

bool

 

IsHandlingReplays()

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

Public function Virtual

void

 

Logout

(
    AController* Exiting
)

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

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

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.

Overridden from AActor

Name Description

Public function Virtual

void

 

Tick

(
    float DeltaSeconds
)

Function called every frame on this Actor.

Deprecated Functions

Name Description

Public function Virtual Const

FString

 

GetDefaultGameClassPath

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

Deprecated in favor of PreloadContentForURL on GameInstance

Public function Virtual Const

TSubclassOf<...

 

GetGameModeClass

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

Deprecated in favor of OverrideGameModeClass on GameInstance

Public function Virtual

void

 

SendPlayer

(
    APlayerController* aPlayer,
    const FString& URL
)

SendPlayer is not in use, call ClientTravel directly instead

Public function Virtual

void

 

SetBandwidthLimit

(
    float AsyncIOBandwidthLimit
)

AsyncIOBandwidthLimit is no longer configurable

Public function Virtual

void

 

StartNewPlayer

(
    APlayerController* NewPlayer
)

StartNewPlayer has been split into InitializeHUDForPlayer and HandleStartingNewPlayer

Public function Static

FString

 

StaticGetFullGameClassName

(
    FString const& Str
)

Deprecated in favor of GetGameModeForName on GameMapsSettings

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