Events and Order

Mods, more specifically children of the Mod class can override certain methods in order to provide functionality at particular steps in the game's initialization process. These methods are called events.

Available Events

  • Loaded This event is fired very early in the startup process, right after assets are loaded but before the game actually starts (in more technical language, it is called right before GameManager.Awake). As it is the first method to be ran on a mod, you can use it to initialize certain fields or print debug messages. At this stage, ID pools are unavailable, along with all Mod methods related to game content. Do not use this method to affect the game in any way.

  • RegisterContent This method is ran after Semi initializes all ID pools and APIs relevant to adding prefabricated content into the game (but note: not yet ready to instantiate any). Certain APIs are also scheduled to refresh after all RegisterContent methods are ran in all mods, such as the localization API. While executing RegisterContent, the mod enters registering mode, allowing for the execution of all methods related to registering or loading content (such as the set of methods starting with Register). This is the only event with this property, and once RegisterContent is finished, the mod leaves registering mode for the rest of the game's runtime. Note: While it is possible to register and initialize content all in this method, there is currently no hard dependency system in Semi and therefore loading order of mods is not guaranteed. This means that if your mod depends on accessing content from other mods, such as a gun that fires a random projectile from any other gun, you might miss out on certain entries added later. It is best to register entries in this method, save them into a field, and then initialize them in the next event.

  • InitializeContent This event is ran after all mods have had their RegisterContent method executed. Its purpose is to allow mods to safely access ID pools with the knowledge that all mods have already registered their content and therefore it is possible to obtain references to their entries. The mod is not in registering mode during this event.

  • Deserialize(string) The string argument passed to this method is the string previously saved in the save file through the use of the Serialize method. You can do anything you want with this string, including deserializing it from JSON, splitting it and then saving entries at certain indexes into fields, etc., in order to implement persistence into your mod content. In the context of starting the game, this event is ran after Loaded and before RegisterContent. It will however also fire when changing save files through the Options menu. Note: Even if the mod does not have saved data in the save file, this method will still be called, with null being passed as the argument.

  • string Serialize This event is ran when the game saves your progress - for example, when you quit it or return to the breach. You can return any string from this method, including null, and it will be saved alongside all other data in the save slot. This same string will later be passed to the Deserialize event when the save slot is loaded. You can use Serialize and Deserialize to implement persistence in your mod.

Last updated