AGameStateBase
#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.
Signature
UCLASS() class AGameStateBase : public AInfo 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.
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());
} See Also
Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
| 5.0 | stable | — |
Feedback
Was this helpful?