UGameplayStatics::GetGameState
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintPure
Description
Returns the current GameStateBase for the world, or null if it cannot be retrieved. Unlike GetGameMode, GameState is replicated and accessible on both server and clients.
Caveats & Gotchas
- • Returns AGameStateBase*, not AGameState*. If your project uses AGameState (the class with ElapsedTime and PlayerArray), cast the result before accessing those members.
- • Can return null briefly during level transition — the new GameState is not fully replicated to clients immediately after travel. Add a null guard or defer access to a short delay after BeginPlay.
- • Avoid calling this every tick without caching the result; the lookup traverses through the UWorld object graph on each call.
Signature
static ENGINE_API class AGameStateBase* GetGameState(const UObject* WorldContextObject); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Any object in the world to use as context. | — |
Return Type
AGameStateBase* Example
Access game state from any actor C++
AMyGameState* GS = Cast<AMyGameState>(UGameplayStatics::GetGameState(this));
if (GS)
{
float TimeLeft = GS->GetMatchTimeRemaining();
} Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?