Quickstart

This quickstart guide can be followed in Blueprints or C++.

1. GameMode and GameState

Start by creating a subclass of AModularGameMode, and set it as the selected GameMode in the World Settings.

Create a subclass of AModularGameState and set it as the active in the AModularGameMode we created above.

2. Phases

To start creating phases subclass UGameModePhase and add it to the list of PreloadPhases in the AModularGameMode created.

note

All the phases in the PreloadPhases will be instantiated automatically when the AModularGameMode is constructed. The first item in the PreloadPhases will be chosen as the starting phase for the game mode.

To replicate information to the clients, create a UGameStatePhase and set it up in the GameStatePhaseClass of the UGameModePhase created above. This will link the two types of phases together, making the UGameStatePhase be instantiated with the UGameModePhase.

There is no limit to the amount of phases that can be created and loaded. For multiplayer games, be considerate with the amount of information that will be replicated when preloading too many phases.

tip

To reduce the number of phases that are loaded initially, phases can be loaded at runtime using the method LoadPhase of the AModularGameMode. When a new UGameModePhase is loaded, the corresponding UGameStatePhase will also be loaded and replicated to clients.

3. Implementing phases

Phases (UGameModePhase and UGameStatePhase) have three different events that can be overridden to implement custom logic:

  • The Setup event is triggered when the phase is loaded. including if it was preloaded.
  • The OnStartPhase event is triggered when the phase is activated, e.g. when changing phases.
  • The OnEndPhase event is triggered each time the phase is deactivated.

Read more in the phases section.

4. Changing phases

To change to a new phase start by retrieving the new UGameModePhase class by using the method LoadPhase if the phase is unloaded, or FindPhaseByClass if the phase is already loaded.

Then execute the ChangePhase method with the UGameModePhase instance. The respective UGameStatePhase will also be run.

warning

Multicast RPCs will not be instantly available on newly loaded UGameStatePhase because of replication latency. To make sure data arrives in the client as soon as possible on a newly loaded UGameStatePhase use replicated properties instead.