Skip to content

interface/actor singleton magic cache [ue plugin]

Notifications You must be signed in to change notification settings

scott-hf/SingletonUtil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Before

bulletshooter3

After

spawninstance2

TLDR

  • Call "Get Singleton Interface" to find, cache, and return an Actor or UObject with given interface. This is "best practice" approach and will remove the hard dependency references between your assets
  • If you don't want to create an interface, you can find, cache, and return an AActor of a given class. This works fine too but will not remove the hard dependency references between your assets ( assuming you are calling this from a blueprint to find another blueprint )

Intent

  • De-couple more, cache easier, and remove clutter from variables in your blueprints - while remaining performant
  • Call singleton interface functions from c++, without caring about BP implementation. IE: set up a c++ interface, create a BP object with that interface in the world, and call it from c++
  • Flexibility for ease of use OR following best practices. Best practices state to de-couple your blueprints and singleton-based interface calls enable that. But if you're just trying to get shit done, call "Get Singleton Actor" - you'll have a direct reference to the actor still, but you won't have to cache it locally in every blueprint that needs to talk to it.

Blueprint Library Functions

image

All blueprint-exposed functions accessible from SD Singleton Subsystem

image

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.

[[Advanced]] Search Parameters for finding your UObject. Usually default search params work but just in case, here are some options

image

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.

Special Thanks

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