> For the complete documentation index, see [llms.txt](https://wiki.redmodding.org/scripting-cyberpunk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.redmodding.org/scripting-cyberpunk/redscript/language-reference/scriptables/scriptableservice.md).

# ScriptableService

{% hint style="info" %}
For more documentation and examples: <https://github.com/psiberx/cp2077-codeware/wiki#scriptable-services>
{% endhint %}

{% hint style="info" %}
`ScriptableService` is only available with [Codeware](/scripting-cyberpunk/introduction/tools-and-frameworks/codeware.md)
{% endhint %}

`ScriptableService` are singletons that are created on game start and live forever, at any point you're able to get a reference to one.

## Example

```swift
module MyMod

public class MyService extends ScriptableService {
  private cb func OnLoad() {
    FTLog("Scripts loaded");
  }

  private cb func OnReload() {
    FTLog("Scripts reloaded");
  }

  private cb func OnInitialize() {
    FTLog("Game instance initialized, can access game systems");
  }

  private cb func OnUninitialize() {
    FTLog("Game is shutting down");
  }

  public static final func GetInstance() -> ref<MyService> {
    return GameInstance.GetScriptableServiceContainer().GetService(n"MyMod.MyService") as MyService;
  }
}
```

To get a reference to your `ScriptableService`, all you need is to call the `GetInstance` method.

{% tabs %}
{% tab title="Redscript" %}

```swift
let myService: ref<MyService> = MyService.GetInstance();

// ...
```

{% hint style="info" %}
If you have defined your service in a module, make sure the module has been imported or define the snippet in the same module.
{% endhint %}
{% endtab %}

{% tab title="Lua" %}

```lua
local myService = MyMod_MyService.GetInstance()

-- ...
```

{% endtab %}
{% endtabs %}

## Persistence

Similar to [ScriptableSystem](/scripting-cyberpunk/redscript/language-reference/scriptables/scriptablesystem.md), `ScriptableService` also supports persistence for properties with all types except for `String`, `Variant`, and `ResRef` (and arrays of these types). These properties are instead stored and saved globally.

For more documentation about persistence, look here: [Persistence](/scripting-cyberpunk/redscript/language-reference/persistence.md)
