Skip to content

SingletonScriptableObject

Eric Lowry edited this page Nov 10, 2026 · 1 revision

Namespace: Lowry.Utils

public abstract class SingletonScriptableObject<T> : LowryScriptable
    where T : ScriptableObject

💡General Information

Provides a cached static lookup for a ScriptableObject type. IL_ScriptableRefs inherits from this class. It finds an existing asset; it does not create one.

📄Properties

Instance

public static T Instance { get; }

Returns the cached instance if it still exists. Otherwise it searches in order:

  1. Resources.FindObjectsOfTypeAll<T>() for already loaded objects.
  2. Resources.LoadAll<T>("") if no loaded objects were found.
  3. In the Unity Editor only, AssetDatabase if neither earlier search found anything.

If the selected search finds zero or multiple results, returns null and logs an error in Editor or DEBUG builds. It does not combine all three searches or detect unloaded duplicates when a loaded instance is found.

On success, caches the instance and assigns HideFlags.DontUnloadUnusedAsset. In the Editor, access also adds the instance to Player Settings' preloaded assets if it is not already listed. Ensure the asset is included in a player build through preloaded assets, Resources, or a scene reference; the player's lookup cannot search the AssetDatabase.

📄Methods

Init()

public void Init ()

Available only when UNITY_EDITOR is defined. Accesses Instance to initialize the lookup and logs an error if it returns null. There is no public setter or explicit cache-reset method.

Clone this wiki locally