posts from @hthrflwrs tagged #idk either

also:


hthrflwrs
@hthrflwrs

it should surprise absolutely nobody that it took approximately three minutes for me to go from using scriptable objects to doing code crimes with them


psilocervine
@psilocervine
public abstract class SingletonScriptableObject<T> : ScriptableObject where T : ScriptableObject
    {
        private static T _instance = null;
        public static T Instance
        {
            get
            {
                if (_instance) return _instance;
                
                var instances = Resources.FindObjectsOfTypeAll<T>();
                
                if (instances.Length > 0)
                {
                    _instance = instances[0];
                }
                else
                {
                    Debug.LogError(typeof(T) + "instance not found!");
                }

                if (instances.Length > 1)
                {
                    Debug.LogError("More than one instance of " + typeof(T) + " found!");
                }

                return _instance;
            }
        }
    }

just inherit from this and slam jam the created object in your resources folder


hthrflwrs
@hthrflwrs

"HANK! NO! YOU CAN'T MAKE YOUR SCRIPTABLE OBJECTS SINGLETONS!! THE BENEFIT OF SCRIPTABLE OBJECTS IS THAT THEY REQUIRE DEPENDENCY INJECTION THROUGH THE EDITOR!!!! MAKING THEM SINGLETONS TAKES AWAY THEIR PRIMARY STRENGTH AS AN ARCHITECTURING TOOL!!! HAAAAAANK!!!!!!"