AGameModeBase::GetGameState
#include "GameFramework/GameModeBase.h"
Access: public
Specifiers: const
Description
Returns the current GameState cast to the requested type. Equivalent to Cast<T>(GameState) but more concise and expressive in game mode code.
Caveats & Gotchas
- • Returns nullptr if the cast fails because the live GameState is not a T. Always check the return value before dereferencing.
- • This helper only exists on AGameModeBase (server-side). On clients, call UWorld::GetGameState<T>() instead.
Signature
template< class T >
T* GetGameState() const Return Type
T* Example
Read custom game state from game mode C++
void AMyGameMode::OnPlayerScored(APlayerController* PC)
{
if (AMyGameState* GS = GetGameState<AMyGameState>())
{
GS->AddScore(PC, 1);
}
} Version History
Introduced in: 4.14
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?