AGameStateBase

GameStateBase is a class that manages the game's global state, and is spawned by GameModeBase.

Windows
MacOS
Linux

Inheritance Hierarchy

References

Module

Engine

Header

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

Include

#include "GameFramework/GameStateBase.h"

Syntax

class AGameStateBase : public AInfo

Remarks

GameStateBase is a class that manages the game's global state, and is spawned by GameModeBase. It exists on both the client and the server and is fully replicated.

Variables

Name Description

Public variable

AGameModeBase &...

 

AuthorityGameMode

Instance of the current game mode, exists only on the server.

Protected variable

bool

 

bReplicatedHasBegunPlay

Replicated when GameModeBase->StartPlay has been called so the client will also start play

Public variable

TSubclassOf< AG...

 

GameModeClass

Class of the server's game mode, assigned by GameModeBase.

Protected variable

uint32

 

NumServerWorldTimeSecondsDeltas

The number of server world time deltas accumulated in SumServerWorldTimeSecondsDelta - used for computing the mean

Public variable

TArray< APlayer...

 

PlayerArray

Array of all PlayerStates, maintained on both server and clients (PlayerStates are always relevant)

Protected variable

float

 

ReplicatedWorldTimeSeconds

Server TimeSeconds. Useful for syncing up animation and gameplay.

Protected variable

float

 

ServerWorldTimeSecondsDelta

The difference from the local world's TimeSeconds and the server world's TimeSeconds.

Protected variable

float

 

ServerWorldTimeSecondsUpdateFrequency

Frequency that the server updates the replicated TimeSeconds from the world.

Public variable

TSubclassOf< AS...

 

SpectatorClass

Class used by spectators, assigned by GameModeBase.

Protected variable

double

 

SumServerWorldTimeSecondsDelta

Cumulative sum of computed server world time deltas for smoothed-averaging

Protected variable

FTimerHandle

 

TimerHandle_UpdateServerTimeSeconds

Handle for efficient management of the UpdateServerTimeSeconds timer

Constructors

Name Description

Public function

AGameStateBase

(
    const FObjectInitializer& ObjectIn...
)

Functions

Name Description

Public function Virtual

void

 

AddPlayerState

(
    APlayerState* PlayerState
)

Add PlayerState to the PlayerArray

Public function Virtual

void

 

AsyncPackageLoaded

(
    UObject* Package
)

Allow game states to react to asset packages being loaded asynchronously

Public function Const

const AGameM...

 

GetDefaultGameMode()

Helper to return the default object of the GameModeBase class corresponding to this GameState.

Public function Const

const T *...

 

GetDefaultGameMode()

Helper template to returns the GameModeBase default object cast to the right type

Public function Virtual Const

float

 

GetPlayerRespawnDelay

(
    AController* Controller
)

Returns how much time needs to be spent before a player can respawn

Public function Virtual Const

float

 

GetPlayerStartTime

(
    AController* Controller
)

Returns the time that should be used as when a player started

Public function Const

APlayerState...

 

GetPlayerStateFromUniqueNetId

(
    const FUniqueNetIdWrapper& InPlaye...
)

Returns the player state for a specified unique player Id

Public function Virtual Const

float

 

GetServerWorldTimeSeconds()

Returns the simulated TimeSeconds on the server, will be synchronized on client and server

Public function Virtual

void

 

HandleBeginPlay()

Called by game mode to set the started play bool

Public function Virtual Const

bool

 

HasBegunPlay()

Returns true if the world has started play (called BeginPlay on actors)

Public function Virtual Const

bool

 

HasMatchEnded()

Returns true if the match can be considered ended. Defaults to false.

Public function Virtual Const

bool

 

HasMatchStarted()

Returns true if the world has started match (called MatchStarted callbacks)

Protected function Virtual

void

 

OnRep_GameModeClass()

GameModeBase class notification callback.

Protected function Virtual

void

 

OnRep_ReplicatedHasBegunPlay()

By default calls BeginPlay and StartMatch

Protected function Virtual

void

 

OnRep_ReplicatedWorldTimeSeconds()

Allows clients to calculate ServerWorldTimeSecondsDelta

Protected function Virtual

void

 

OnRep_SpectatorClass()

Callback when we receive the spectator class

Public function Virtual

void

 

ReceivedGameModeClass()

Called when the GameClass property is set (at startup for the server, after the variable has been replicated on clients)

Public function Virtual

void

 

ReceivedSpectatorClass()

Called when the SpectatorClass property is set (at startup for the server, after the variable has been replicated on clients)

Public function Virtual

void

 

RemovePlayerState

(
    APlayerState* PlayerState
)

Remove PlayerState from the PlayerArray.

Public function Virtual

void

 

SeamlessTravelTransitionCheckpoint

(
    bool bToTransitionMap
)

Called during seamless travel transition twice (once when the transition map is loaded, once when destination map is loaded)

Protected function Virtual

void

 

UpdateServerTimeSeconds()

Called periodically to update ReplicatedWorldTimeSeconds

Overridden from AActor

Name Description

Public function Virtual

void

 

PostInitializeComponents()

Allow actors to initialize themselves on the C++ side after all of their components have been initialized, only called during gameplay

Overridden from UObject

Name Description

Public function Virtual Const

void

 

GetLifetimeReplicatedProps

(
    TArray< FLifetimeProperty >& OutLi...
)

Returns the properties used for network replication, this needs to be overridden by all actor classes with native replicated properties

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