Course contentsShow
← Unreal Engine Game Development
Lesson 147 of 8802. The Gameplay FrameworkFree lesson

Defining Global Communication via Subsystems

You will create persistent, global managers that exist outside the Actor lifecycle to handle game-wide state and cross-level data persistence.

In this lesson, you will learn how to create persistent, global managers that exist outside the standard Actor lifecycle to handle game-wide state and data persistence.

Why Avoid Actors for Global Logic?

Up until now, you have likely used Actors or ActorComponents to handle your game logic. While powerful, Actors are tied to the level lifecycle—when you travel from one level to another, all your Actors are destroyed, and your data is wiped. If you want to track a player’s "Total Lifetime XP" or a "Global Server Connection" that survives level transitions, you shouldn't be hunting for a specific Actor in a specific level.

This is where Subsystems come in. Subsystems are automatically managed classes that live for the duration of their scope (GameInstance, World, or Engine) and don't need to be placed in a level.

The GameInstance Subsystem

The most common type for your needs is the UGameInstanceSubsystem. Because the GameInstance persists for the entire time your game is running, any data stored in a GameInstanceSubsystem will persist perfectly across level loads.

To create one, simply inherit from UGameInstanceSubsystem. You don't need to spawn it or maintain a reference to it; Unreal handles that for you. You can access it from anywhere in your code using GetGameInstance()->GetSubsystem<UMyCustomSubsystem>().

Here is a quick look at how you define one:

// UMyGlobalManager.h
UCLASS()
class UMyGlobalManager : public UGameInstanceSubsystem
{
    GENERATED_BODY()

public:
    // This variable now persists even when you switch levels!
    UPROPERTY()
    int32 TotalSessionScore = 0;

    void AddToGlobalScore(int32 Amount) { TotalSessionScore += Amount; }
};

Why This is Better

By moving global logic into a Subsystem, you decouple your managers from the level design. You no longer need to worry about "Is the GameMode valid?" or "Has the PlayerController spawned yet?" You simply request the Subsystem, and if it exists, it provides the data you need. It turns your architecture from "Actor-dependent" into a centralized, robust service-based system.

Key Takeaway: Subsystems act as persistent, auto-managed global services that provide data access across level transitions without requiring an Actor to exist in the world.