UWorld::GetGameState
#include "Engine/World.h"
Access: public
Specifiers: const
Description
Returns the current GameState instance cast to the template type. Returns null if the GameState hasn't been set or the cast fails.
Signature
template<class T> T* GetGameState() const Return Type
T* Caveats & Gotchas
- • The non-template overload returns AGameStateBase* — use the template version in typed C++ code to avoid manual casting.
- • GameState is replicated to all clients and is valid on both server and client after BeginPlay. It may be null very early in initialization before the GameState actor is created.
- • Do not confuse with GetAuthGameMode() — GameState is accessible everywhere; GameMode is server-only.
Example
Access a typed GameState C++
AMyGameState* GS = GetWorld()->GetGameState<AMyGameState>();
if (GS)
{
int32 Score = GS->GetTeamScore();
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?