psilocervine

but wife city is two words

56k warning


cohost (arknights)
cohost.org/arkmints

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!!!!!!"



You must log in to comment.

in reply to @hthrflwrs's post:

I've built entire systems (the TutorialManager in Assassin's Creed Rebellion comes to mind) where a singleton monobehaviour runs a list of scriptableobjects that all descend from a base type that provides a coroutine chunk in an abstract Execute function.

The eternal lesson: data and code is the same and one can be made to look like the other

Weirdly, there are almost no coroutines in 1000xResist. I've gotten into the habit of just making elaborate stateful Update methods instead lol