Repository navigation
SingletonScriptableObject
Namespace: Lowry.Utils
public abstract class SingletonScriptableObject<T> : LowryScriptable
where T : ScriptableObjectProvides a cached static lookup for a ScriptableObject type. IL_ScriptableRefs inherits from this class. It finds an existing asset; it does not create one.
public static T Instance { get; }Returns the cached instance if it still exists. Otherwise it searches in order:
-
Resources.FindObjectsOfTypeAll<T>()for already loaded objects. -
Resources.LoadAll<T>("")if no loaded objects were found. - In the Unity Editor only,
AssetDatabaseif 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.
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.
👉🏻 Download InputLayers on the Unity Asset Store!