RealDocs

AGameStateBase

class Engine Since 4.14
#include "GameFramework/GameStateBase.h"
Access: public Specifiers: UCLASS

Description

Replicated actor that holds authoritative game state visible to all clients — the client-accessible counterpart to `AGameModeBase`. Contains `PlayerArray` (all connected `APlayerState` objects) and exposes server time. Subclass to add replicated match score, round number, team data, or any state clients need to read.

Caveats & Gotchas

  • Unlike GameMode (server-only), GameState is replicated to all clients — avoid server-only logic here.
  • `PlayerArray` is populated automatically as players join and leave; do not manually add or remove entries.
  • Access via `GetWorld()->GetGameState<AMyGameState>()` on any machine.

Signature

UCLASS() class AGameStateBase : public AInfo

Examples

Add replicated score to a subclass C++
UPROPERTY(Replicated, BlueprintReadOnly)
int32 TeamAScore = 0;

// Access on any machine
AMyGameState* GS = GetWorld()->GetGameState<AMyGameState>();
if (GS) { int32 Score = GS->TeamAScore; }
Iterate all connected players C++
for (APlayerState* PS : GetWorld()->GetGameState()->PlayerArray)
{
    UE_LOG(LogGame, Log, TEXT("Player: %s"), *PS->GetPlayerName());
}

Functions (17)

Lifecycle
5
Access Type Name
public function AGameStateBase::HandleBeginPlay
public function AGameStateBase::PostInitializeComponents
public function AGameStateBase::AsyncPackageLoaded
public function AGameStateBase::ReceivedGameModeClass
public function AGameStateBase::ReceivedSpectatorClass
Networking
3
Access Type Name
public function AGameStateBase::GetLifetimeReplicatedProps
public function AGameStateBase::GetServerWorldTimeSeconds
public function AGameStateBase::SeamlessTravelTransitionCheckpoint
State
9
Access Type Name
public function AGameStateBase::HasBegunPlay
public function AGameStateBase::HasMatchStarted
public function AGameStateBase::AddPlayerState
public function AGameStateBase::GetDefaultGameMode
public function AGameStateBase::GetPlayerRespawnDelay
public function AGameStateBase::GetPlayerStateFromUniqueNetId
public function AGameStateBase::HasMatchEnded
public function AGameStateBase::RemovePlayerState
public function AGameStateBase::GetPlayerStartTime

Properties

Access Type Name
public property AGameStateBase::AuthorityGameMode
public property AGameStateBase::GameModeClass
public property AGameStateBase::PlayerArray
public property AGameStateBase::SpectatorClass

Version History

Introduced in: 4.14

Version Status Notes
5.6 stable
5.0 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.