# Singletons

{% hint style="success" %}
verified: 2025-11-20 version: v39
{% endhint %}

A singleton is a server-authoritative `MorpheusActor` which is spawned exactly once, when the server starts up. A singleton can [replicate](https://docs.msquared.io/creation/unreal-development/getting-started/networking/replicated-properties) data to game clients, and game clients can send data to the server with server [RPCs](https://docs.msquared.io/creation/unreal-development/getting-started/networking/morpheus-rpcs).

Singletons are useful for the common case where you want to put a single easily-accessed object in charge of some behaviour. If no replication is required, you could handle this with server-only logic on a subsystem. However, if you want to communicate between the client and server, you need a `MorpheusActor`, so you need to use a singleton.

## How are they set up? <a href="#how-are-they-set-up" id="how-are-they-set-up"></a>

To make a singleton, create a new blueprint class from a `MorpheusActor`.

In the World Settings panel, locate the `Singletons` section, and add your new class to the `Additional Singletons` array.

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-1407257f55f553e934e50b0c9ba11ee371ed364e%2Fimage.png?alt=media" alt=""><figcaption><p>Additional Singletons</p></figcaption></figure>

If you want this singleton behaviour but for non-Morpheus Actors, use the `Non Morpheus Singletons` array. Disconnected instances of your class will be spawned on the server and all clients. (This is similar to a subsystem, but preferable if you want control over which levels the object is present in.)

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-c5db2db6d9543a2dcf3e4f3407f830357abb1636%2Fimage.png?alt=media" alt=""><figcaption><p>Non Morpheus Singletons</p></figcaption></figure>

{% hint style="warning" %}
Singletons do not spawn automatically during automated tests. Manually spawn the required Singletons when creating automated tests that rely on them.
{% endhint %}

## How to access your singleton

* The easiest way to get your singleton actor is using the `GetActorOfClass` method.
  * This will fail (return null) if called before the singleton has been spawned.
* To defer until your singleton is available, you can use the bootflow subsystem's function `HandleCommonActorsSpawned` in your actor's `BeginPlay`/`MorpheusBeginPlay`:

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-e5bff5a4f26b18b5ec6f4d038eeec5c81567e1f9%2Fimage.png?alt=media" alt=""><figcaption><p>This example will cache the singleton of type <code>BPM_VendingMachineManager</code> once it has been spawned. Other bootflow steps after <code>HandleCommonActorsSpawned</code> would also work here, e.g. <code>HandleBootflowFinished</code>.</p></figcaption></figure>

* Alternatively, you can use the global function `GetSingletonOnceAvailable`, specifying the `SingletonClass`.
  * The result will be a base `Actor`, so you will need to cast to the class you need.

<figure><img src="https://1456550285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FoWTlPaoHd1McSakqMigu%2Fuploads%2Fgit-blob-43dd01bf31e893a96a2501e7bac6e55c76c5412d%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: 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:

```
GET https://docs.msquared.io/creation/unreal-development/features-and-tutorials/singletons.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
