Singletons

The Singletons subsystem provides a generic, attribute-driven singleton pattern for the three Paragon base object types: MonoBehaviour, plain C# object, and ScriptableObject. Each singleton variant uses a lazy-initialization chain (find → load → create) with auto-creation of persistent assets in the editor, and an optional auto-initialization system that eagerly loads singletons at startup.

Architecture

spinner

Initialization Flow

spinner

Key Concepts

Concept
Description

Lazy initialization

Singletons are created on first access to Instance. The resolution chain varies by type (find → load → create).

Auto-creation

In the editor, if no asset exists, one is automatically created and saved to Resources/{AssetPath}.

[SingletonSettings]

Attribute controlling behavior: asset path, DontDestroyOnLoad, InitializeOnLoad, visibility flags.

SingletonInitializer

Runs before scene load, eagerly initializes all singletons marked InitializeOnLoad = true.

Three variants

SingletonBehaviour<T> (MonoBehaviour), SingletonScriptableObject<T> (ScriptableObject), SingletonObject<T> (plain C#).

Quick Start

MonoBehaviour Singleton

ScriptableObject Singleton

Plain C# Object Singleton

Classes

Class
Description

MonoBehaviour singleton — find → load → create chain, DontDestroyOnLoad support

Plain C# singleton — creates via new T(), no Unity asset backing

ScriptableObject singleton — load → create chain, auto-saves .asset in editor

Attribute controlling singleton behavior (asset path, initialization, visibility)

Runtime bootstrap that eagerly initializes InitializeOnLoad singletons

See Also

Last updated