AGameMode
- Module
- Game
- Header
#include "Game/AGameMode.h"- Namespace
Mowo- Reflection
- Reflected by MowoHeaderTool
Properties
| Type | Name | Description |
|---|---|---|
TSubclassOf<APawn> | defaultPawnClass | Classes to spawn. nullptr = the base type (APawn / APlayerController / AGameState). Editable in Details and saved with the level, so a designer picks the pawn instead of a constructor naming it; a Visual Scripting class counts as a pawn when it derives from APawn. |
TSubclassOf<APlayerController> | playerControllerClass | |
TSubclassOf<AGameState> | gameStateClass | |
int32_t | playerIndex | Default 0. |
bool | spawnLocalPlayerOnStart | Default true. |
Constructors
| Signature | Name | Description |
|---|---|---|
AGameMode() = default | AGameMode |
Public functions
| Returns | Name | Description |
|---|---|---|
void | InitGame | Called by MWorld::InitializeGameMode right after the game mode itself spawns — before StartMatch. |
void | StartMatch | Spawns GameState + PlayerController + default pawn, possesses, flips match state to InProgress. |
APawn* | SpawnDefaultPawn | |
APawn* | RestartPlayer | UE5 RestartPlayer: spawn a defaultPawnClass pawn at the APlayerStart matching playerStartIndex (-1 = any) and possess it with the given controller. |
APlayerStart* | FindPlayerStart | |
void | SetStartOverride | Play From Here (the editor's right-click on the level): the next pawn the game mode places for the LOCAL player spawns at this transform instead of at an APlayerStart. |
void | ClearStartOverride | |
bool | HasStartOverride | |
AGameState* | GetGameState | |
APlayerController* | GetPlayerController | |
bool | HasMatchStarted | |
void | PostLogin | Player arrival and departure, UE's PostLogin / Logout. |
void | Logout | |
MulticastDelegate<AController*, APawn*>& | OnPostLogin | |
MulticastDelegate<AController*>& | OnLogout | |
void | NotifyPostLogin | |
void | NotifyLogout | |
int32_t | GetNumPlayers | |
void | Tick | Advances match time on the game state. |
Function details
AGameMode
AGameMode() = defaultInitGame
virtual void InitGame()Called by MWorld::InitializeGameMode right after the game mode itself spawns — before StartMatch. Override for rule setup that must precede any spawning.
StartMatch
virtual void StartMatch()Spawns GameState + PlayerController + default pawn, possesses, flips match state to InProgress. Idempotent (second call no-ops). A dedicated server sets spawnLocalPlayerOnStart false first — the match starts with no local player and pawns arrive per connection through RestartPlayer.
SpawnDefaultPawn
virtual APawn* SpawnDefaultPawn()RestartPlayer
virtual APawn* RestartPlayer(AController* controller, int32_t playerStartIndex = -1)UE5 RestartPlayer: spawn a defaultPawnClass pawn at the APlayerStart matching playerStartIndex (-1 = any) and possess it with the given controller. The join path (FNetSession::ServerSpawnPawnFor) calls this once per connecting player.
FindPlayerStart
APlayerStart* FindPlayerStart(int32_t index) constSetStartOverride
static void SetStartOverride(const Vec3& location, const Quat& rotation)Play From Here (the editor's right-click on the level): the next pawn the game mode places for the LOCAL player spawns at this transform instead of at an APlayerStart. One-shot — consumed by that placement and cleared by the editor when play stops — and process-wide because the game mode that will read it does not exist yet when the editor decides where play begins.
ClearStartOverride
static void ClearStartOverride()HasStartOverride
static bool HasStartOverride()GetGameState
AGameState* GetGameState() constGetPlayerController
APlayerController* GetPlayerController() constHasMatchStarted
bool HasMatchStarted() constPostLogin
virtual void PostLogin(AController* controller, APawn* pawn)Player arrival and departure, UE's PostLogin / Logout. PostLogin fires once a controller holds its first pawn — the local player's at StartMatch, a joining peer's after RestartPlayer — and Logout right before a departing player's controller is torn down. Override the virtuals in a game mode subclass or bind the delegates from anywhere.
Logout
virtual void Logout(AController* controller)OnPostLogin
MulticastDelegate<AController*, APawn*>& OnPostLogin()OnLogout
MulticastDelegate<AController*>& OnLogout()NotifyPostLogin
void NotifyPostLogin(AController* controller, APawn* pawn)NotifyLogout
void NotifyLogout(AController* controller)GetNumPlayers
int32_t GetNumPlayers() constTick
void Tick(float deltaSeconds) overrideAdvances match time on the game state.