Navigation
API > API/Runtime > API/Runtime/Engine
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.
| Name | AGameMode |
| Type | class |
| Header File | /Engine/Source/Runtime/Engine/Classes/GameFramework/GameMode.h |
| Include Path | #include "GameFramework/GameMode.h" |
Syntax
UCLASS (MinimalAPI)
class AGameMode : public AGameModeBase
Inheritance Hierarchy
- UObjectBase → UObjectBaseUtility → UObject → AActor → AInfo → AGameModeBase → AGameMode
Derived Classes
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
AGameMode
(
const FObjectInitializer& ObjectInitializer |
GameFramework/GameMode.h |
Variables
Public
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| bDelayedStart | uint32 | Whether the game should immediately start when the first player logs in. | GameFramework/GameMode.h |
|
| EngineMessageClass | TSubclassOf< class ULocalMessage > | Contains strings describing localized game agnostic messages. | GameFramework/GameMode.h | |
| InactivePlayerArray | TArray< TObjectPtr< class APlayerState > > | PlayerStates of players who have disconnected from the server (saved in case they reconnect) | GameFramework/GameMode.h | |
| MinRespawnDelay | float | Minimum time before player can respawn after dying. | GameFramework/GameMode.h |
|
| NumBots | int32 | Number of non-human players (AI controlled but participating as a player). | GameFramework/GameMode.h |
|
| NumPlayers | int32 | Current number of human players. | GameFramework/GameMode.h |
|
| NumSpectators | int32 | Current number of spectators. | GameFramework/GameMode.h |
|
| NumTravellingPlayers | int32 | Number of players that are still traveling from a previous map | GameFramework/GameMode.h |
|
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void AbortMatch() |
Report that a match has failed due to unrecoverable error | GameFramework/GameMode.h |
|
virtual void AddInactivePlayer
(
APlayerState* PlayerState, |
Add PlayerState to the inactive list, remove from the active list | GameFramework/GameMode.h | |
| Broadcast a string to all players. | GameFramework/GameMode.h | ||
virtual void BroadcastLocalized
(
AActor* Sender, |
Broadcast a localized message to all players. | GameFramework/GameMode.h | |
virtual void EndMatch () |
Transition from InProgress to WaitingPostMatch. | GameFramework/GameMode.h |
|
virtual bool FindInactivePlayer
(
APlayerController* PC |
Attempt to find and associate an inactive PlayerState with entering PC. | GameFramework/GameMode.h | |
FName GetMatchState() |
Returns the current match state, this is an accessor to protect the state machine flow | GameFramework/GameMode.h |
|
virtual FString GetNetworkNumber() |
Get local address | GameFramework/GameMode.h | |
virtual bool GetTravelType() |
Return true if we want to travel_absolute, used by RestartGame by default | GameFramework/GameMode.h | |
virtual void HandleDisconnect
(
UWorld* InWorld, |
Handles when a player is disconnected, before the session does | GameFramework/GameMode.h | |
virtual void HandleStartingNewPlayer_Implementation
(
APlayerController* NewPlayer |
GameFramework/GameMode.h | ||
virtual bool IsMatchInProgress() |
Returns true if the match state is InProgress or other gameplay state | GameFramework/GameMode.h |
|
virtual void NotifyPendingConnectionLost
(
const FUniqueNetIdRepl& ConnectionUniqueId |
Called when a connection closes before getting to PostLogin() | GameFramework/GameMode.h | |
virtual void OverridePlayerState
(
APlayerController* PC, |
Override PC's PlayerState with the values in OldPlayerState as part of the inactive player handling | GameFramework/GameMode.h | |
virtual bool PlayerCanRestart_Implementation
(
APlayerController* Player |
GameFramework/GameMode.h | ||
void PlayerSwitchedToSpectatorOnly
(
APlayerController* PC |
Will remove the controller from the correct count then add them to the spectator count. | GameFramework/GameMode.h | |
virtual void PostCommitMapChange () |
Called from CommitMapChange after unloading previous level and loading new level+sublevels. | GameFramework/GameMode.h | |
| Called from CommitMapChange before unloading previous level. Used for asynchronous level streaming | GameFramework/GameMode.h | ||
void RemovePlayerControllerFromPlayerCount
(
APlayerController* PC |
Removes the passed in player controller from the correct count for player/spectator/tranistioning | GameFramework/GameMode.h | |
virtual void RestartGame() |
Restart the game, by default travel to the current map | GameFramework/GameMode.h |
|
virtual void Say
(
const FString& Msg |
Exec command to broadcast a string to all players | GameFramework/GameMode.h |
|
virtual void SetSeamlessTravelViewTarget
(
APlayerController* PC |
SetViewTarget of player control on server change | GameFramework/GameMode.h | |
virtual void StartMatch () |
Transition from WaitingToStart to InProgress. | GameFramework/GameMode.h |
|
Overridden from AGameModeBase
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual bool CanServerTravel
(
const FString& URL, |
Returns true if allowed to server travel | GameFramework/GameMode.h | |
virtual int32 GetNumPlayers() |
Returns number of active human players, excluding spectators | GameFramework/GameMode.h | |
virtual int32 GetNumSpectators() |
Returns number of human players currently spectating | GameFramework/GameMode.h | |
virtual void HandleSeamlessTravelPlayer
(
AController*& C |
Handles reinitializing players that remained through a seamless level transition called from C++ for players that finished loading after the server | GameFramework/GameMode.h | |
virtual bool HasMatchEnded() |
Returns true if the match state is WaitingPostMatch or later | GameFramework/GameMode.h | |
virtual bool HasMatchStarted() |
Returns true if the match start callbacks have been called | GameFramework/GameMode.h | |
| Initialize the game. | GameFramework/GameMode.h | ||
virtual void InitSeamlessTravelPlayer
(
AController* NewController |
Handles initializing a seamless travel player, handles logic similar to InitNewPlayer | GameFramework/GameMode.h | |
virtual bool IsHandlingReplays() |
Returns true if replays will start/stop during gameplay starting/stopping | GameFramework/GameMode.h | |
virtual void Logout
(
AController* Exiting |
Called when a Controller with a PlayerState leaves the game or is destroyed | GameFramework/GameMode.h | |
virtual void PostLogin
(
APlayerController* NewPlayer |
Called after a successful login. | GameFramework/GameMode.h | |
virtual void PostSeamlessTravel () |
Called after a seamless level transition has been completed on the new GameMode. | GameFramework/GameMode.h | |
virtual bool SpawnPlayerFromSimulate
(
const FVector& NewLocation, |
Used in the editor to spawn a PIE player after the game has already started | GameFramework/GameMode.h | |
virtual void StartPlay() |
Transitions to calls BeginPlay on actors. | GameFramework/GameMode.h | |
virtual void StartToLeaveMap () |
Start the transition out of the current map. | GameFramework/GameMode.h |
Overridden from AActor
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void Tick
(
float DeltaSeconds |
Function called every frame on this Actor. | GameFramework/GameMode.h |
Protected
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void HandleLeavingMap() |
Called when the match transitions to LeavingMap | GameFramework/GameMode.h | |
virtual void HandleMatchAborted() |
Called when the match transitions to Aborted | GameFramework/GameMode.h | |
virtual void HandleMatchHasEnded() |
Called when the map transitions to WaitingPostMatch | GameFramework/GameMode.h | |
virtual void HandleMatchHasStarted() |
Called when the state transitions to InProgress | GameFramework/GameMode.h | |
virtual void HandleMatchIsWaitingToStart() |
Called when the state transitions to WaitingToStart | GameFramework/GameMode.h | |
void K2_OnSetMatchState
(
FName NewState |
Implementable event to respond to match state changes | GameFramework/GameMode.h |
|
virtual void OnMatchStateSet() |
Overridable virtual function to dispatch the appropriate transition functions before GameState and Blueprints get SetMatchState calls. | GameFramework/GameMode.h | |
bool ReadyToEndMatch() |
Returns true if ready to End Match. Games should override this | GameFramework/GameMode.h |
|
bool ReadyToStartMatch() |
Returns true if ready to Start Match. Games should override this | GameFramework/GameMode.h |
|
virtual void SetMatchState
(
FName NewState |
Updates the match state and calls the appropriate transition functions | GameFramework/GameMode.h |