Subsystem life cycle

Hello,

I want to use a subsystem that has a life cycle similar to the LocalPlayerSubsystems, but that can exist on dedicated servers. Does this exists or anyone have an idea of what is the best way of creating this?

thanks,

There varius subsystems you can use:

If you want server only you can initialize one only if it’s running in dedicated server mode

As far as I can see, there is only Engine, Editor, GameInstance and LocalPlayer subsystems, out of which none seems to fit your needs.

There is a PR for Game Mode Subsystem, which is more like what you want - it exists on the server, created when the level is created, and destroyed when the level is changed: https://github.com/EpicGames/UnrealEngine/pull/5896

Until it’s accepted, you can’t use subsystems to achieve what you want, I’m afraid. You can do it manually tho as you would have done in the pre-4.22 era: on the BeginPlay of Game Mode, construct a new object of yours (your “subsystem”) with the Outer of the Game Mode - this way, it’s gonna get created and destroyed alongside Game Mode (or you can do it on any other class that better fits the lifecycle you’re targeting).

I’ve made a UGameInstanceSubsystem subsystem. But the question is the same for all subsystem : How can I check that I’m on the dedicated server in UGameInstanceSubsystem::ystem(UObject* Outer)?

There’s actually one more type of subsystem that’s not documented in the subsystem webdocs: UWorldSubsystem(API Doc)

It has the same lifetime as UWorld, which, IIRC, gets reinitialized on every map change, which is required to change gamemode, so technically it has the same lifetime as a gamemode.

2 Likes