> For the complete documentation index, see [llms.txt](https://ss3d.gitbook.io/dev-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ss3d.gitbook.io/dev-guide/guidelines/code-design/subsystem-locator.md).

# SubSystems Locator

The <mark style="color:purple;">**SubSystems**</mark> class is used to easily find any subsystem that has been registered on it.

It helps us avoid falling into the [Singleton pattern](https://gameprogrammingpatterns.com/singleton.html), and does something similar to the [Service Locator pattern](https://gameprogrammingpatterns.com/service-locator.html). Also good for performance reasons, It can handle over a million calls every frame with no issues.

## Using the SubSystems class

To register a new subsystem you can call the <mark style="color:purple;">**SubSystems**</mark>**.**<mark style="color:green;">**Register**</mark>**(**<mark style="color:blue;">**this**</mark>**)** method, passing in a class that extends from <mark style="color:purple;">**SubSystem**</mark> or <mark style="color:purple;">**NetworkSubSystem**</mark>, it'll add that subsystem into a dictionary of subsystems, preventing two of the same subsystem from existing.

Then you can get this subsystem from somewhere else using <mark style="color:purple;">**SubSystems**</mark>**.**<mark style="color:green;">**Get**</mark>**<**<mark style="color:purple;">**T**</mark>**>()**

## <mark style="color:yellow;">**⚠️**</mark>\*\* \*\*<mark style="color:red;">**IMPORTANT!**</mark>

Note that is done automatically by classes inheriting <mark style="color:purple;">**SubSystem**</mark> and <mark style="color:purple;">**NetworkedSubSystem**</mark>. They both register on <mark style="color:green;">**Awake**</mark> and unregister on <mark style="color:green;">**Destroy**</mark>:

<pre><code><strong>public class SubSystem : Actor
</strong>    {
        protected override void OnAwake()
        {
            base.OnAwake();
            SubSystemLocator.Register(this);
        }

        protected override void OnDestroyed()
        {
            base.OnDestroyed();
            SubSystemLocator.Unregister(this);
        }
    }
</code></pre>

## Examples

<details>

<summary>Getting the spawned players list</summary>

<mark style="color:purple;">EntitySpawnSubSystem</mark> entitySpawnSubSystem = <mark style="color:purple;">SubSystems</mark>.<mark style="color:green;">Get</mark><<mark style="color:purple;">EntitySpawnSubSystem</mark>>();

<mark style="color:purple;">List</mark><<mark style="color:purple;">PlayerControllable</mark>> playersToAssign = entitySpawnSubSystem.<mark style="color:blue;">SpawnedPlayers</mark>;

</details>

<details>

<summary>Ending the round after detonating a nuke</summary>

*<mark style="color:blue;">// Ends the round, regardless of how many objectives were completed</mark>* <mark style="color:purple;">SubSystems</mark>.<mark style="color:green;">Get</mark><<mark style="color:purple;">GamemodeSubSystem</mark>>().<mark style="color:green;">EndRound</mark>();

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ss3d.gitbook.io/dev-guide/guidelines/code-design/subsystem-locator.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
