Programming Subsystems

Subsystems introduced Unreal Engine 4.22 is elegant method for creating gameplay managers of any kind.

Updated about 3 years ago

Subsystems introduced Unreal Engine 4.22 is elegant method for creating gameplay managers of any kind.

  • It minimizes the need to put a lot of "manager code" into extended classes of UGameInstance, AWorldSettings, AGameModeBase. It's common to end up with many various systems in a single class, which is messy and more difficult to maintain over time.

  • Instead now we can use automatically instanced objects called subsystems. Engine creates an instance of this object together with its "parent" object, i.e. Game Instance, World. You don't need to store a pointer to it anywhere.

  • You can have as many subsystems for a given "parent" as you want, i.e Audio Manager and UI Manager as Game Instance subsystems, Weather Manager and Monster Spawn as World subsystems.

Subsystem Inherits from Engine version
Engine UEngineSubsystem 4.22
Editor UEditorSubsystem 4.22
Game Instance UGameInstanceSubsystem 4.22
Local Player ULocalPlayerSubsystem 4.22
World UWorldSubsystem 4.22

General Aspects

  • The subsystem's lifecycle and existence depend on their owner. For instance, Worldsubsystems will only be alive as long as their owning UWorld is valid. Likewise, ULocalPlayerSubsystems will only exist where and when their respective ULocalPlayer exists.

  • Subsystems cannot have internally-handled replicated properties/functions. However, you can "tie" replicated UObjects to interact with them and feed them the information.

UMySubsystem::Function() {
  MyRepActor->RepFunction();
}

AMyRepActor::RepFunction_Implementation() {
  MySubsystem->MyOtherFunction(); 
}

Official resources