AGameMode

Inheritance Hierarchy

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

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

Functions

Name Description

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

bool

 

FindInactivePlayer

(
    APlayerController * PC
)

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

Public function Virtual

FString

 

GetDefaultGameClassPath

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

Public function Virtual

TSubclassOf <...

 

GetGameModeClass

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

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

Games should override these functions to deal with their game specific logic.

Public function Virtual

void

 

HandleStartingNewPlayer_Implementation

(
    APlayerController * NewPlayer
)

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

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

True if ready to End Match. Games should override this

Protected function

bool

 

ReadyToStartMatch()

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

 

Say

(
    const FString & Msg
)

Exec command to broadcast a string to all players

Public function Virtual

void

 

SendPlayer

(
    APlayerController * aPlayer,
    const FString & URL
)

Public function Virtual

void

 

SetBandwidthLimit

(
    float AsyncIOBandwidthLimit
)

Alters the synthetic bandwidth limit for a running game.

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

 

StartNewPlayer

(
    APlayerController * NewPlayer
)

Public function Static

FString

 

StaticGetFullGameClassName

(
    FString const& Str
)

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

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
)

Initializing 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()

Starting/pausing/resetting the game.

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.

References

Module

Engine

Header

Runtime/Engine/Classes/GameFramework/GameMode.h