UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AGameMode Class Reference

#include <GameMode.h>

+ Inheritance diagram for AGameMode:

Public Member Functions

virtual ENGINE_API FString GetNetworkNumber ()
 
ENGINE_API void PlayerSwitchedToSpectatorOnly (APlayerController *PC)
 
ENGINE_API void RemovePlayerControllerFromPlayerCount (APlayerController *PC)
 
virtual ENGINE_API bool GetTravelType ()
 
virtual ENGINE_API void Say (const FString &Msg)
 
virtual ENGINE_API void Broadcast (AActor *Sender, const FString &Msg, FName Type=NAME_None)
 
virtual ENGINE_API void BroadcastLocalized (AActor *Sender, TSubclassOf< ULocalMessage > Message, int32 Switch=0, APlayerState *RelatedPlayerState_1=NULL, APlayerState *RelatedPlayerState_2=NULL, UObject *OptionalObject=NULL)
 
virtual ENGINE_API void AddInactivePlayer (APlayerState *PlayerState, APlayerController *PC)
 
virtual ENGINE_API bool FindInactivePlayer (APlayerController *PC)
 
virtual ENGINE_API void OverridePlayerState (APlayerController *PC, APlayerState *OldPlayerState)
 
virtual ENGINE_API void SetSeamlessTravelViewTarget (APlayerController *PC)
 
virtual ENGINE_API void PreCommitMapChange (const FString &PreviousMapName, const FString &NextMapName)
 
virtual ENGINE_API void PostCommitMapChange ()
 
virtual ENGINE_API void NotifyPendingConnectionLost (const FUniqueNetIdRepl &ConnectionUniqueId)
 
virtual ENGINE_API void HandleDisconnect (UWorld *InWorld, UNetDriver *NetDriver)
 
virtual ENGINE_API void Tick (float DeltaSeconds) override
 
virtual ENGINE_API void InitGame (const FString &MapName, const FString &Options, FString &ErrorMessage) override
 
virtual ENGINE_API void StartPlay () override
 
virtual ENGINE_API bool HasMatchStarted () const override
 
virtual ENGINE_API bool HasMatchEnded () const override
 
virtual ENGINE_API void PostLogin (APlayerController *NewPlayer) override
 
virtual ENGINE_API void Logout (AController *Exiting) override
 
virtual ENGINE_API int32 GetNumPlayers () override
 
virtual ENGINE_API int32 GetNumSpectators () override
 
virtual ENGINE_API bool IsHandlingReplays () override
 
virtual ENGINE_API void HandleStartingNewPlayer_Implementation (APlayerController *NewPlayer) override
 
virtual ENGINE_API bool PlayerCanRestart_Implementation (APlayerController *Player) override
 
virtual ENGINE_API void PostSeamlessTravel () override
 
virtual ENGINE_API void HandleSeamlessTravelPlayer (AController *&C) override
 
virtual ENGINE_API void InitSeamlessTravelPlayer (AController *NewController) override
 
virtual ENGINE_API bool CanServerTravel (const FString &URL, bool bAbsolute) override
 
virtual ENGINE_API void StartToLeaveMap () override
 
virtual ENGINE_API bool SpawnPlayerFromSimulate (const FVector &NewLocation, const FRotator &NewRotation) override
 

Public Attributes

uint32 bDelayedStart: 1
 
int32 NumSpectators
 
int32 NumPlayers
 
int32 NumBots
 
float MinRespawnDelay
 
int32 NumTravellingPlayers
 
TSubclassOf< class ULocalMessageEngineMessageClass
 
TArray< TObjectPtr< class APlayerState > > InactivePlayerArray
 

Protected Member Functions

virtual ENGINE_API void SetMatchState (FName NewState)
 
virtual ENGINE_API void OnMatchStateSet ()
 
ENGINE_API void K2_OnSetMatchState (FName NewState)
 
virtual ENGINE_API void HandleMatchIsWaitingToStart ()
 
ENGINE_API bool ReadyToStartMatch ()
 
virtual ENGINE_API void HandleMatchHasStarted ()
 
ENGINE_API bool ReadyToEndMatch ()
 
virtual ENGINE_API void HandleMatchHasEnded ()
 
virtual ENGINE_API void HandleLeavingMap ()
 
virtual ENGINE_API void HandleMatchAborted ()
 

Protected Attributes

FName MatchState
 
float InactivePlayerStateLifeSpan
 
int32 MaxInactivePlayers
 
bool bHandleDedicatedServerReplays
 

Detailed Description

GameMode is a subclass of GameModeBase that behaves like a multiplayer match-based game. It has default behavior for picking spawn points and match state. If you want a simpler base, inherit from GameModeBase instead.

Member Function Documentation

◆ AddInactivePlayer()

void AGameMode::AddInactivePlayer ( APlayerState PlayerState,
APlayerController PC 
)
virtual

Add PlayerState to the inactive list, remove from the active list

◆ Broadcast()

void AGameMode::Broadcast ( AActor Sender,
const FString &  Msg,
FName  Type = NAME_None 
)
virtual

Broadcast a string to all players.

◆ BroadcastLocalized()

void AGameMode::BroadcastLocalized ( AActor Sender,
TSubclassOf< ULocalMessage Message,
int32  Switch = 0,
APlayerState RelatedPlayerState_1 = NULL,
APlayerState RelatedPlayerState_2 = NULL,
UObject OptionalObject = NULL 
)
virtual

Broadcast a localized message to all players. Most message deal with 0 to 2 related PlayerStates. The LocalMessage class defines how the PlayerState's and optional actor are used.

◆ CanServerTravel()

bool AGameMode::CanServerTravel ( const FString &  URL,
bool  bAbsolute 
)
overridevirtual

◆ FindInactivePlayer()

bool AGameMode::FindInactivePlayer ( APlayerController PC)
virtual

Attempt to find and associate an inactive PlayerState with entering PC.
@Returns true if a PlayerState was found and associated with PC.

◆ GetNetworkNumber()

FString AGameMode::GetNetworkNumber ( )
virtual

Get local address

◆ GetNumPlayers()

int32 AGameMode::GetNumPlayers ( )
overridevirtual

◆ GetNumSpectators()

int32 AGameMode::GetNumSpectators ( )
overridevirtual

◆ GetTravelType()

bool AGameMode::GetTravelType ( )
virtual

Return true if we want to travel_absolute, used by RestartGame by default

◆ HandleDisconnect()

void AGameMode::HandleDisconnect ( UWorld InWorld,
UNetDriver NetDriver 
)
virtual

Handles when a player is disconnected, before the session does

◆ HandleLeavingMap()

void AGameMode::HandleLeavingMap ( )
protectedvirtual

Called when the match transitions to LeavingMap

◆ HandleMatchAborted()

void AGameMode::HandleMatchAborted ( )
protectedvirtual

Called when the match transitions to Aborted

◆ HandleMatchHasEnded()

void AGameMode::HandleMatchHasEnded ( )
protectedvirtual

Called when the map transitions to WaitingPostMatch

◆ HandleMatchHasStarted()

void AGameMode::HandleMatchHasStarted ( )
protectedvirtual

Called when the state transitions to InProgress

◆ HandleMatchIsWaitingToStart()

void AGameMode::HandleMatchIsWaitingToStart ( )
protectedvirtual

Called when the state transitions to WaitingToStart

◆ HandleSeamlessTravelPlayer()

void AGameMode::HandleSeamlessTravelPlayer ( AController *&  C)
overridevirtual

◆ HandleStartingNewPlayer_Implementation()

void AGameMode::HandleStartingNewPlayer_Implementation ( APlayerController NewPlayer)
overridevirtual

◆ HasMatchEnded()

bool AGameMode::HasMatchEnded ( ) const
overridevirtual

Returns true if the match state is WaitingPostMatch or later

◆ HasMatchStarted()

bool AGameMode::HasMatchStarted ( ) const
overridevirtual

◆ InitGame()

void AGameMode::InitGame ( const FString &  MapName,
const FString &  Options,
FString &  ErrorMessage 
)
overridevirtual

◆ InitSeamlessTravelPlayer()

void AGameMode::InitSeamlessTravelPlayer ( AController NewController)
overridevirtual

◆ IsHandlingReplays()

bool AGameMode::IsHandlingReplays ( )
overridevirtual

◆ K2_OnSetMatchState()

ENGINE_API void AGameMode::K2_OnSetMatchState ( FName  NewState)
protected

Implementable event to respond to match state changes

◆ Logout()

void AGameMode::Logout ( AController Exiting)
overridevirtual

◆ NotifyPendingConnectionLost()

void AGameMode::NotifyPendingConnectionLost ( const FUniqueNetIdRepl ConnectionUniqueId)
virtual

Called when a connection closes before getting to PostLogin()

Parameters
ConnectionUniqueIdthe unique id on the connection, if known (may be very early and impossible to know)

◆ OnMatchStateSet()

void AGameMode::OnMatchStateSet ( )
protectedvirtual

Overridable virtual function to dispatch the appropriate transition functions before GameState and Blueprints get SetMatchState calls.

◆ OverridePlayerState()

void AGameMode::OverridePlayerState ( APlayerController PC,
APlayerState OldPlayerState 
)
virtual

Override PC's PlayerState with the values in OldPlayerState as part of the inactive player handling

◆ PlayerCanRestart_Implementation()

bool AGameMode::PlayerCanRestart_Implementation ( APlayerController Player)
overridevirtual

◆ PlayerSwitchedToSpectatorOnly()

void AGameMode::PlayerSwitchedToSpectatorOnly ( APlayerController PC)

Will remove the controller from the correct count then add them to the spectator count.

◆ PostCommitMapChange()

void AGameMode::PostCommitMapChange ( )
virtual

Called from CommitMapChange after unloading previous level and loading new level+sublevels. Used for asynchronous level streaming

◆ PostLogin()

void AGameMode::PostLogin ( APlayerController NewPlayer)
overridevirtual

◆ PostSeamlessTravel()

void AGameMode::PostSeamlessTravel ( )
overridevirtual

◆ PreCommitMapChange()

void AGameMode::PreCommitMapChange ( const FString &  PreviousMapName,
const FString &  NextMapName 
)
virtual

Called from CommitMapChange before unloading previous level. Used for asynchronous level streaming

Parameters
PreviousMapName- Name of the previous persistent level
NextMapName- Name of the persistent level being streamed to

◆ ReadyToEndMatch()

ENGINE_API bool AGameMode::ReadyToEndMatch ( )
protected

Returns true if ready to End Match. Games should override this

◆ ReadyToStartMatch()

ENGINE_API bool AGameMode::ReadyToStartMatch ( )
protected

Returns true if ready to Start Match. Games should override this

◆ RemovePlayerControllerFromPlayerCount()

void AGameMode::RemovePlayerControllerFromPlayerCount ( APlayerController PC)

Removes the passed in player controller from the correct count for player/spectator/tranistioning

◆ Say()

void AGameMode::Say ( const FString &  Msg)
virtual

Exec command to broadcast a string to all players

◆ SetMatchState()

void AGameMode::SetMatchState ( FName  NewState)
protectedvirtual

Updates the match state and calls the appropriate transition functions

◆ SetSeamlessTravelViewTarget()

void AGameMode::SetSeamlessTravelViewTarget ( APlayerController PC)
virtual

SetViewTarget of player control on server change

◆ SpawnPlayerFromSimulate()

bool AGameMode::SpawnPlayerFromSimulate ( const FVector NewLocation,
const FRotator NewRotation 
)
overridevirtual

◆ StartPlay()

void AGameMode::StartPlay ( )
overridevirtual

◆ StartToLeaveMap()

void AGameMode::StartToLeaveMap ( )
overridevirtual

◆ Tick()

void AGameMode::Tick ( float  DeltaSeconds)
overridevirtual

Member Data Documentation

◆ bDelayedStart

uint32 AGameMode::bDelayedStart

Whether the game should immediately start when the first player logs in. Affects the default behavior of ReadyToStartMatch

◆ bHandleDedicatedServerReplays

bool AGameMode::bHandleDedicatedServerReplays
protected

If true, dedicated servers will record replays when HandleMatchHasStarted/HandleMatchHasStopped is called

◆ EngineMessageClass

TSubclassOf<class ULocalMessage> AGameMode::EngineMessageClass

Contains strings describing localized game agnostic messages.

◆ InactivePlayerArray

TArray<TObjectPtr<class APlayerState> > AGameMode::InactivePlayerArray

PlayerStates of players who have disconnected from the server (saved in case they reconnect)

◆ InactivePlayerStateLifeSpan

float AGameMode::InactivePlayerStateLifeSpan
protected

Time a playerstate will stick around in an inactive state after a player logout

◆ MatchState

FName AGameMode::MatchState
protected

What match state we are currently in

◆ MaxInactivePlayers

int32 AGameMode::MaxInactivePlayers
protected

The maximum number of inactive players before we kick the oldest ones out

◆ MinRespawnDelay

float AGameMode::MinRespawnDelay

Minimum time before player can respawn after dying.

◆ NumBots

int32 AGameMode::NumBots

number of non-human players (AI controlled but participating as a player).

◆ NumPlayers

int32 AGameMode::NumPlayers

Current number of human players.

◆ NumSpectators

int32 AGameMode::NumSpectators

Current number of spectators.

◆ NumTravellingPlayers

int32 AGameMode::NumTravellingPlayers

Number of players that are still traveling from a previous map


The documentation for this class was generated from the following files: