Programming Subsystems

From UE4: Community Wiki
Jump to: navigation, search


Assumed Knowledge[edit]

You have Unreal Engine C++ experience.

Introduction[edit]

Subsystems were introduced into Unreal Engine 4.22 and provide an 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 Lifecycle[edit]

A Subsystem contains the lifecycle methods Initialize and Deinitialize, which will be invoked automatically [1] and its lifetime will be determined by the engine class that it was inherited from [2].

Table 1: Lifetime Inheritance Table

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

Accessing Subsystems[edit]

A Subsystem may be referenced from a Blueprint Graph in the same way a variable is referenced.

Official Resources[edit]

  1. Epic Games, Inc. "Programming Subsystem" [Online]. Available: https://docs.unrealengine.com/en-US/Programming/Subsystems/index.html
  2. Epic Games, Inc. "USubsystem" [Online]. Available: https://docs.unrealengine.com/en-US/API/Runtime/Engine/Subsystems/USubsystem/index.html

References[edit]