UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AGameStateBase Class Reference

#include <GameStateBase.h>

+ Inheritance diagram for AGameStateBase:

Public Member Functions

virtual void AsyncPackageLoaded (UObject *Package)
 
ENGINE_API const AGameModeBase * GetDefaultGameMode () const
 
template<class T >
const T * GetDefaultGameMode () const
 
virtual ENGINE_API double GetServerWorldTimeSeconds () const
 
virtual ENGINE_API bool HasBegunPlay () const
 
virtual ENGINE_API bool HasMatchStarted () const
 
virtual ENGINE_API bool HasMatchEnded () const
 
virtual ENGINE_API float GetPlayerStartTime (AController *Controller) const
 
virtual ENGINE_API float GetPlayerRespawnDelay (AController *Controller) const
 
virtual ENGINE_API void GetLifetimeReplicatedProps (TArray< FLifetimeProperty > &OutLifetimeProps) const
 
ENGINE_API APlayerStateGetPlayerStateFromUniqueNetId (const FUniqueNetIdWrapper &InPlayerId) const
 
virtual ENGINE_API void ReceivedGameModeClass ()
 
virtual ENGINE_API void ReceivedSpectatorClass ()
 
virtual ENGINE_API void SeamlessTravelTransitionCheckpoint (bool bToTransitionMap)
 
virtual ENGINE_API void AddPlayerState (APlayerState *PlayerState)
 
virtual ENGINE_API void RemovePlayerState (APlayerState *PlayerState)
 
virtual ENGINE_API void HandleBeginPlay ()
 
virtual ENGINE_API void PostInitializeComponents () override
 

Public Attributes

TSubclassOf< AGameModeBase > GameModeClass
 
TObjectPtr< AGameModeBase > AuthorityGameMode
 
TSubclassOf< ASpectatorPawnSpectatorClass
 
TArray< TObjectPtr< APlayerState > > PlayerArray
 

Protected Member Functions

virtual ENGINE_API void OnRep_GameModeClass ()
 
virtual ENGINE_API void OnRep_SpectatorClass ()
 
virtual ENGINE_API void OnRep_ReplicatedHasBegunPlay ()
 
virtual ENGINE_API void UpdateServerTimeSeconds ()
 
virtual ENGINE_API void OnRep_ReplicatedWorldTimeSecondsDouble ()
 

Protected Attributes

bool bReplicatedHasBegunPlay
 
double ReplicatedWorldTimeSecondsDouble
 
float ServerWorldTimeSecondsDelta
 
float ServerWorldTimeSecondsUpdateFrequency
 
FTimerHandle TimerHandle_UpdateServerTimeSeconds
 
double SumServerWorldTimeSecondsDelta
 
uint32 NumServerWorldTimeSecondsDeltas
 

Friends

class UDemoNetDriver
 
class FReplayHelper
 

Detailed Description

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.

Member Function Documentation

◆ AddPlayerState()

void AGameStateBase::AddPlayerState ( APlayerState PlayerState)
virtual

Add PlayerState to the PlayerArray

◆ AsyncPackageLoaded()

virtual void AGameStateBase::AsyncPackageLoaded ( UObject Package)
inlinevirtual

Allow game states to react to asset packages being loaded asynchronously

◆ GetDefaultGameMode() [1/2]

const AGameModeBase * AGameStateBase::GetDefaultGameMode ( ) const

Helper to return the default object of the GameModeBase class corresponding to this GameState. This object is not safe to modify.

◆ GetDefaultGameMode() [2/2]

template<class T >
const T * AGameStateBase::GetDefaultGameMode ( ) const
inline

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

◆ GetLifetimeReplicatedProps()

void AGameStateBase::GetLifetimeReplicatedProps ( TArray< FLifetimeProperty > &  OutLifetimeProps) const
virtual

◆ GetPlayerRespawnDelay()

float AGameStateBase::GetPlayerRespawnDelay ( AController Controller) const
virtual

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

Reimplemented in AGameState.

◆ GetPlayerStartTime()

float AGameStateBase::GetPlayerStartTime ( AController Controller) const
virtual

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

Reimplemented in AGameState.

◆ GetPlayerStateFromUniqueNetId()

APlayerState * AGameStateBase::GetPlayerStateFromUniqueNetId ( const FUniqueNetIdWrapper InPlayerId) const

Returns the player state for a specified unique player Id

◆ GetServerWorldTimeSeconds()

double AGameStateBase::GetServerWorldTimeSeconds ( ) const
virtual

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

◆ HandleBeginPlay()

void AGameStateBase::HandleBeginPlay ( )
virtual

Called by game mode to set the started play bool

Reimplemented in AGameState.

◆ HasBegunPlay()

bool AGameStateBase::HasBegunPlay ( ) const
virtual

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

◆ HasMatchEnded()

bool AGameStateBase::HasMatchEnded ( ) const
virtual

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

Reimplemented in AGameState.

◆ HasMatchStarted()

bool AGameStateBase::HasMatchStarted ( ) const
virtual

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

Reimplemented in AGameState.

◆ OnRep_GameModeClass()

void AGameStateBase::OnRep_GameModeClass ( )
protectedvirtual

GameModeBase class notification callback.

◆ OnRep_ReplicatedHasBegunPlay()

void AGameStateBase::OnRep_ReplicatedHasBegunPlay ( )
protectedvirtual

By default calls BeginPlay and StartMatch

◆ OnRep_ReplicatedWorldTimeSecondsDouble()

void AGameStateBase::OnRep_ReplicatedWorldTimeSecondsDouble ( )
protectedvirtual

Allows clients to calculate ServerWorldTimeSecondsDelta

◆ OnRep_SpectatorClass()

void AGameStateBase::OnRep_SpectatorClass ( )
protectedvirtual

Callback when we receive the spectator class

◆ PostInitializeComponents()

void AGameStateBase::PostInitializeComponents ( )
overridevirtual

Reimplemented in AGameState.

◆ ReceivedGameModeClass()

void AGameStateBase::ReceivedGameModeClass ( )
virtual

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

Reimplemented in AGameState.

◆ ReceivedSpectatorClass()

void AGameStateBase::ReceivedSpectatorClass ( )
virtual

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

◆ RemovePlayerState()

void AGameStateBase::RemovePlayerState ( APlayerState PlayerState)
virtual

Remove PlayerState from the PlayerArray.

◆ SeamlessTravelTransitionCheckpoint()

void AGameStateBase::SeamlessTravelTransitionCheckpoint ( bool  bToTransitionMap)
virtual

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

◆ UpdateServerTimeSeconds()

void AGameStateBase::UpdateServerTimeSeconds ( )
protectedvirtual

Called periodically to update ReplicatedWorldTimeSecondsDouble

Friends And Related Symbol Documentation

◆ FReplayHelper

friend class FReplayHelper
friend

◆ UDemoNetDriver

friend class UDemoNetDriver
friend

Member Data Documentation

◆ AuthorityGameMode

TObjectPtr<AGameModeBase> AGameStateBase::AuthorityGameMode

Instance of the current game mode, exists only on the server. For non-authority clients, this will be NULL.

◆ bReplicatedHasBegunPlay

bool AGameStateBase::bReplicatedHasBegunPlay
protected

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

◆ GameModeClass

TSubclassOf<AGameModeBase> AGameStateBase::GameModeClass

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

◆ NumServerWorldTimeSecondsDeltas

uint32 AGameStateBase::NumServerWorldTimeSecondsDeltas
protected

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

◆ PlayerArray

TArray<TObjectPtr<APlayerState> > AGameStateBase::PlayerArray

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

◆ ReplicatedWorldTimeSecondsDouble

double AGameStateBase::ReplicatedWorldTimeSecondsDouble
protected

Server TimeSeconds. Useful for syncing up animation and gameplay.

◆ ServerWorldTimeSecondsDelta

float AGameStateBase::ServerWorldTimeSecondsDelta
protected

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

◆ ServerWorldTimeSecondsUpdateFrequency

float AGameStateBase::ServerWorldTimeSecondsUpdateFrequency
protected

How often the server updates the replicated TimeSeconds from the world. Values mean "update every X seconds", so 0.5 means update every half second. Set to zero to disable periodic updates.

◆ SpectatorClass

TSubclassOf<ASpectatorPawn> AGameStateBase::SpectatorClass

Class used by spectators, assigned by GameModeBase.

◆ SumServerWorldTimeSecondsDelta

double AGameStateBase::SumServerWorldTimeSecondsDelta
protected

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

◆ TimerHandle_UpdateServerTimeSeconds

FTimerHandle AGameStateBase::TimerHandle_UpdateServerTimeSeconds
protected

Handle for efficient management of the UpdateServerTimeSeconds timer


The documentation for this class was generated from the following files: