Subsystems

If you’re looking for the subsystems that SML provides by default, check out the Registry page.

Subsystems are actors that exist only once in the world (similar to Singletons, but not quite) as an instance general manager. These subsystems are accessible from anywhere you have a world context available (f.e. actors). Subsystems allow you to implement custom game state information, for example, that you want to have saved to the save file, or when you want to manage multiple actors or some system from one central point.

For example, the mod Light It Up uses subsystems to create a lamp group system. With this system, every lamp can get information about the current group settings without storing that data again in each lamp instance.

Subsystems can exist on host, client, or both sides of a multiplayer game, possibly replicated, depending on their Replication Policy setting.

If you’re implementing a subsystem in C++ and you override BeginPlay or EndPlay, be sure to call the super functions, or the subsystem will not be handled correctly.

Registering a Subsystem

If you want to have a subsystem you will need at least one class that inherits the ModSubsystem class.

To register a subsystem, you should add it to the Mod Subsystems array of the Game World Module.

GameWorldModule

The subsystems are held by the SubsystemActorManager, that can be obtained using the GetSubsystemActorManager function.

GameWorldModule

Spawning a Subsystem

As long as you have correctly registered the subsystem, there is no need to for you to spawn its actor - SML will take care of spawning it for you. Subsystems are spawned early in the Construction phase and their Begin Play method is called as part of the Initialization phase.

If the actor doesn’t seem to be spawning for some reason, make sure that you have correctly configured its Replication Policy.

Referencing a Subsystem

A subsystem itself is an actor inheriting from ModSubsystem. You can also use subsystems to store data to save states.

You should use the GetSubsystemActor function to reference your desired subsystem.

GameWorldModule

  • The first parameter of the function is a reference to your SubsystemActorManager acquired using the GetSubsystemActorManager function.

  • The second parameter is just a name for the actor in this example ExampleSubsystem.

Consider checking if the retrieved subsystem is valid before trying to do anything with it.