Phases

Phases are classes that enable the developer to build modular game mode structures.

For example, for a multiplayer shooter, the phases could be:

  1. Loading phase: Waits for all players to load in.
  2. Playing phase: Players engage in gameplay as defined by the game mode objectives.
  3. Scoreboard phase: Displays each player's performance based on game objectives.
  4. It cycles back to phase 1 on a new map.

There could be multiple Playing phases that are loaded and unloaded at runtime based for example, in player selection.

Types

There are two types of phases: UGameModePhase and UGameStatePhase. The first one is always required. The latter is only needed if the phase will replicate data to clients (i.e. for multiplayer games).

UGameModePhase

Created only on the server by the AModularGameMode.

Each UGameModePhase provides a GameStatePhaseClass property to indicate the UGameStatePhase that has to be constructed as part of the phase.

UGameStatePhase

Created on server and clients. Can replicate data and RPCs from server to client (but not from clients to server!).

By default, events that are executed by the plugin (described below) only are executed on the server. To execute the events on clients too, the property bReplicatePhaseEvents can be enabled on the Blueprint defaults or the C++ constructor.

Events

Phases offer implementable events that can be used to create game-specific mechanics. These events can be overridden in Blueprints or C++.

Setup

The setup event is triggered whenever the phase is loaded by the plugin. This includes both when is preloaded and when it's loaded at runtime.

OnStartPhase

Triggered each time the phase is activated.

OnEndPhase

Triggered each time the phase is deactivated. The Phase instance remains loaded for reuse the next time it’s needed. It can be unloaded using UnloadPhase of the AModularGameMode.

CanStartPhase

warning

This event is available only for UGameModePhase subclasses.

When AModularGameMode::ChangePhase is executed, the CanStartPhase event will be called to check if the phase can be activated.

If the phase cannot be activated, AModularGameMode will retain the current active phase.

This event allows controlling when specific phases can start. For instance, you may want to prevent the game from entering the scoreboard phase if no match is currently in progress.

Lifetime

Phases share their lifetime with their OuterObject. They are instanced by the server, and are valid until they are unloaded or their respective AModularGameMode or AModularGameState is destroyed.