ScottDunbar.io - SD Singleton Util

SD Singleton Util - Destroyer of hard references and "get actor of class"

A blueprint-exposed, C++ only, singleton utility plugin for Unreal Engine, designed to cache and retrieve singleton instances of actors, interfaces, and global objects.

See it in action here (GIF on front page) : https://github.com/scott-hf/SingletonUtil

TLDR

  • Stop calling "get actor of class" and caching it as a variable

  • Remove hard references between blueprints

Intent

  • De-couple more, cache easier, and remove clutter from variables in your blueprints - while remaining performant

  • Call singleton functions for any actor, component, or interface

  • For actors and components, auto-create the singleton class if it doesn't exist

Notes

- All C++, nothing in the content folder

- All functions exposed to blueprint. Use it in C++ or blueprint - your choice

- The two most commonly used functions are simplified and expose via blueprint function library. To see all functions, retrieve the subsystem.

Features

- Get Singleton Actor: Retrieve or create a singleton instance of an actor.

- Get Singleton Interface: Retrieve a singleton instance of an interface class.

- Global UObject Registry: Register and retrieve global UObjects with optional identifiers.

- Derived Class Caching: Efficiently cache derived classes for retrieval.

- Debug Tools: Inspect the current state of singleton caches for actors and objects.

## Installation

1. Clone or download this repository into your project's `Plugins` folder.

2. Enable the Singleton Util Plugin in your project's plugin settings.

Usage

### 1. Get Singleton Actor

Retrieve a singleton actor within the current world context.

- `WorldContextObject`: Reference to the current world.

- `MyActorClass`: The actor class to retrieve as a singleton.

- `bCreateIfMissing`: If `true`, creates a new instance if none exists.

### 2. Get Singleton Interface

Retrieve a singleton instance of a specific interface.

- `WorldContextObject`: Reference to the current world.

- `MyInterfaceClass`: Interface class to retrieve as a singleton.

- `OutObject`: Receives the object implementing the interface.

### 3. Register and Retrieve Global Objects

Register a global object to make it easily accessible across contexts.

Retrieve a global object by class and optional identifier.

### 4. Advanced Search Parameters

Use `FSD_SingletonSearchParams` for refined search criteria for finding interface singleton objects, such as filtering by object type, name, or actor-only objects.

## Debugging

- Object Cache Snapshot: Retrieve a snapshot of the current object cache.

- Actor Cache Snapshot: Inspect the current actor cache for debugging.

- Interface Cache Snapshot: Inspect the current interface cache for debugging.

## Available on github

If you'd like to build it yourself, you can find the cpp code available here:

https://github.com/scott-hf/SingletonUtil

## Special Thanks

Thank you to avigrail, who helped provided examples on how to declare interface specific return values, among other things

1 Like

Thank you for Providing! 5.5 support any soon;)? All the best!

1 Like

Thanks! I rated this gem 5.0. Hopefully this will be maintained across future versions of Unreal Engine!

+1 to this, would love 5.5 support! Also, I’m a little confused on what the get Singleton interface does? Like I might be dumb but I thought interfaces were just ways to modularly call functions on actors without having to have a hard ref to them so I’m not sure how you would “get” an interface itself