Introduction
Modular Game Modes is a framework that enables developers to break down complex game modes into manageable, interchangeable phases, so they can build flexible and highly organized game mode structures.
Who is this for?
This plugin is perfect for developers who want to streamline their game’s lifecycle, simplify complex game mode logic, and improve code readability. Whether you're creating multiplayer games, or single-player experiences, this plugin is designed to make game mode management effortless.
It is recommended to have an understanding of Unreal Engine's Gameplay Framework before using the plugin. Comprehending the concepts of
AGameModeBase
andAGameStateBase
is specially relevant.
Where to buy?
The plugin is sold on the Lorwen Pyramid Fab.com listing.
About this guide
This guide covers the core features and functionality of the plugin, providing you with a foundational understanding of its capabilities. An example project is included to demonstrate how to effectively implement the plugin in your own projects.
Example Project
A complete example project is provided and can be downloaded from Proton Drive.
About the Example Project
The example project is built entirely in Blueprints and includes:
- Detailed, commented Blueprints
- A straightforward gameplay loop
- Multiplayer support
- Modular phases:
- Lobby
- Loading screen
- Two match modes
- Scoreboard
This example demonstrates just a few of the many ways the plugin can be used. Depending on your game, you may need to create additional phases and customize them with functionality to suit your project’s unique needs.
Release Notes
The plugin is currently in BETA status. As such, some breaking changes are expected between different versions.
There are no more planned updated after v0.2, excluding bugfixes that will happen along the whole life of the product. As soon as the plugin is stabilized, the BETA tag will be removed.
v0.2
Compatible with Unreal Engine versions 5.4 and 5.5.
This updated adds dynamic loading/unloading of phases.
The example project is also expanded to showcase the new dynamism of loading/unloading phases.
v0.1
Only compatible with Unreal Engine 5.4.
This is the first public release of the plugin.
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.
Concepts
This section will explain in detail how each part of the Modular Game Modes
plugin works.
After understanding these key concepts, check out the example project that demonstrates how the plugin can be used.
Phases
Phases are classes that enable the developer to build modular game mode structures.
For example, for a multiplayer shooter, the phases could be:
- Loading phase: Waits for all players to load in.
- Playing phase: Players engage in gameplay as defined by the game mode objectives.
- Scoreboard phase: Displays each player's performance based on game objectives.
- 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.
Modular GameMode
The AModularGameMode
inherits AGameModeBase
, adding methods to create, find and change phases.
An UGameModePhase
is constructed automatically by the AModularGameMode
. To determine which UGameModePhase
are instantiated and available for the game, they should be placed in the AvailablePhases
array of the AModularGameMode
.
Available methods
These are the methods available in the AModularGameMode
:
Modular GameState
AModularGameState
inherits AGameStateBase
adding methods to retrieve phases.
AModularGameState
also provides replication support for properties and NetMulticast
RPCs, to be executed from server to client (and NOT in the opposite direction).
For multiplayer games, each UGameModePhase
should have their respective UGameStatePhase
in UGameModePhase::GameStatePhaseClass
ready in the editor or the C++ constructor, in order to provide replication for that phase.
Available methods
These are the methods available in the AModularGameState
:
Support
Bug reports
To submit a bug report, please include a detailed description of the problem, any specific information for why it could be happening, and the steps to reproduce it.
- Mail: support@lorwenpyramid.com
- Subject: [ModularGameModes: Bug]
Feature requests
To submit a feature request, please include a detailed description of the feature, any specific requirements for how it should be implemented, and a brief explanation of how it will add value to your workflow or address a particular need. Comprehensive information helps with assessing and prioritizing requests more effectively.
Feature development will depend on availability and the complexity of the request. Not every request may be accommodated.
- Mail: support@lorwenpyramid.com
- Subject: [ModularGameModes: Feature Request]
Showcase your project
If you choose to use this plugin, I’d be thrilled to showcase your project or video on my blog to help promote your work and share it with a wider audience. Likewise, any mention in your project credits will be very appreciated, and will provide support to continue developing and maintaining similar tools.
You can write about your project by sending an email to support@lorwenpyramid.com with the subject: [ModularGameModes: Showcase].