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.

Using UModSubsystemHolder

If you want to have a subsystem you will need at least one class that inherits the UModSubsystemHolder class. These holders will spawn and store the references to the subsystems your mod uses.

It has an InitSubsystems function in which you need to spawn the subsystems you want to add and then store the references in attributes.

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

You can use the static K2_GetModSubsystemHolder function to get your holders from other places in the code. This function returns a reference to your holder, which itself has attributes references to the subsystems you initialized in it.

Spawning a Subsystem

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

To spawn one in a subsystem holder (in the InitSubsystems function) you should use the UModSubsystemHolder::SpawnSubsystem function. This function checks if the subsystem is already spawned (f.e. loaded from the save state) and returns the reference to it instead of creating a new one. The first parameter of the function is a reference to your variable which will then reference the newly spawned or found subsystem. The second parameter tells the function for which class to actually look for or which class needs to be created. The third parameter is just a name for the actor.

To spawn a subsystem in BP you should use the UModSubsystemHolder::K2_SpawnSubsystem function.