For the complete documentation index, see llms.txt. This page is also available as Markdown.

ScriptableSystem

ScriptableSystem is a built-in class, they're singletons that are bounded to game sessions as they are created and disposed with game sessions.

Example

module MyMod

public class MySystem extends ScriptableSystem {
  public func OnAttach() -> Void {
    FTLog(s"\(this.GetClassName())#OnAttach");
  }

  public func OnDetach() -> Void {
    FTLog(s"\(this.GetClassName())#OnDetach");
  }

  public func OnRestored(saveVersion: Int32, gameVersion: Int32) -> Void {
    FTLog(s"\(this.GetClassName())#OnRestored | \(saveVersion) | \(gameVersion)");
  }

  public func GetData() -> Float {
    return GetPlayer(this.GetGameInstance()).GetGunshotRange();
  }

  public static final func GetInstance(gameInstance: GameInstance) -> ref<MySystem> {
    return GameInstance.GetScriptableSystemsContainer(gameInstance).Get(n"MyMod.MySystem") as MySystem; // don't forget the namespace if you're using modules
  }
}

To get a reference to MySystem, all you need to do is to give a GameInstance reference:

If you have defined your system in a module, make sure the module has been imported or define the snippet in the same module.

For CET, you don't specify the parameter for GameInstance as it's given automagically.

Persistence

ScriptableSystems can persist data of all types except for String, Variant, and ResRef (and arrays of these types) between game sessions. If a property is marked as persistent it will be stored within a save file and will persist the next time that save file is loaded.

For more documentation about persistence, look here: Persistence

Last updated