RealDocs

UWorld::GetAuthGameMode

function Engine Since 4.0
#include "Engine/World.h"
Access: public Specifiers: const

Description

Returns the current AGameModeBase instance cast to the template type. Only valid on the server or in standalone — always returns null on clients.

Signature

template<class T> T* GetAuthGameMode() const

Return Type

T*

Caveats & Gotchas

  • This function always returns null on clients. To share game data with clients, put it in GameState instead — GameState is replicated.
  • The non-template overload returns AGameModeBase* — use the typed template version in C++ to avoid manual casting.
  • Returns null if called before the GameMode has been created (e.g. very early world initialization).

Example

Access the GameMode on the server C++
if (HasAuthority())
{
	AMyGameMode* GM = GetWorld()->GetAuthGameMode<AMyGameMode>();
	if (GM)
	{
		GM->EndMatch();
	}
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.