Unite 2016 - Overthrowing the MonoBehaviour Tyranny in a Glorious Scriptable Object Revolution
Why Stack Overflow recommends it
Stack Overflow users link it when answering Unity questions about using ScriptableObjects for weapon data, enum replacements, dictionary keys and sharing state between scenes.
Recommended by 3 people across 3 different months, 2017 to 2019.
Why Game Development Stack Exchange recommends it
Game Development Stack Exchange users link it when answering Unity questions about storing scene state, inventories or game state in ScriptableObjects instead of MonoBehaviours.
Recommended by 2 people across 2 different months, 2019 to 2020.
What it is
A Unite 2016 conference talk by Richard Fine of Unity Technologies on the ScriptableObject class, comparing it with MonoBehaviour and walking through patterns such as data tables, extendable enums, reload-proof singletons and delegate objects. It ends with a demo built on the Tanks project.
What people said
Recommends Scott Chamberlain · 2017-01 · Stack Overflow · on “Comparer for dictionary of System.Enum without boxing”
Seeing your example in the comments, and that this is for Unity, watch this clip from Unite 2016 [this video] . It talks about using Scriptable Objects instead of enums for dictionary keys. What you would do is have public class Program { protected Dictionary<ScriptableObject, string> dict = new Dictionary<ScriptableObject, string>(); } public class ProgramChild1 : Program { public void Test() { dict.Add(MyEnum1.One.Instance, "One"); dict.Add(MyEnum1.Two.Instance, "Two"); dict.Add(MyEnum1.Three.Instance, "Three"); string result; dict.TryGetValue(MyEnum1.Two.Instance, out result); } } public class ProgramChild2 : Program { public void Test() { dict.Add(MyEnum2.Four.Instance, "One"); dict.Add(MyEnu
Recommends pasotee · 2018-04 · Stack Overflow · on “Unity3D fps weapon pickup/switch”
One good advice I can give you is to use scriptable objects for all your weapons and have a list of all the ones you collected. You might find useful to create a scriptable object for the weapons with all the info it holds such as mesh, fire rate and others and just read the data from it. This way you can switch the weapons by reading the data from the SO and pick-up the weapons by adding a SO to the list. You can find more information about this here: [this video]
Recommends JeffUK · 2019-01 · Game Development Stack Exchange · on “Can a prefab of a complete Unity scene be created?”
It might be better to use a ScriptableObject to store the state of your scene then re-load it. [this video] This would allow you to dynamically generate new scenes from code.
Recommends Jack Mariani · 2019-07 · Stack Overflow · on “ScriptableObject identity”
SO = Scriptable Object Unity SO already have an identity and they can, themselves, be used as itentifiers. You may see a specific example in this youtube video - 23:41 [this video] , where a SO may be used as an identifier to replace an enum to differentiate the damage types of a given weapon. To have an identifier you can just use this code. [CreateAssetMenu(menuName = "Simple Identifier")] public class J_Identifier : ScriptableObject {} And you can reference it inside other classes, or even inside itself. public class Something : MonoBehaviour { //the instance of the identifier J_Identifier identifier; private bool CheckIdentifierWith(J_Identifier otherIdentifier) => identifier == otherIdentifi
Recommends JesseTG · 2020-02 · Game Development Stack Exchange · on “How can I implement an inventory that stores different types of items?”
Assuming you're using Unity like the tags suggest, I strongly recommend watching these [this video] two [LINK] talks about `ScriptableObject`s. They may give you exactly the inspiration you need.
Cites Candid Moon _Max_ · 2019-02 · Game Development Stack Exchange · on “How to Implement a Very Simple Game State Manager in Unity?”
Reload-proof Singleton There is no way without black magic, but here is that black magic ^_^: using UnityEngine; using System.IO; #if UNITY_EDITOR using UnityEditor; #endif #if UNITY_EDITOR public static class ScriptableObjectUtility { /// <summary> /// This makes it easy to create, name and place unique new ScriptableObject asset files. /// </summary> public static T CreateAsset<T>(string path, string name) where T : ScriptableObject { T asset = ScriptableObject.CreateInstance<T>(); if (path == string.Empty) { path = "Assets"; } else if (Path.GetExtension(path) != string.Empty) { path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), string.Empty); } strin
Cites Jack Mariani · 2019-05 · Stack Overflow · on “What is the best practice to load ScriptableObjects to single prefab/multiple prefabs?”
TLDR : use Monobehvaiour to implement an enemy. Use SO just to setup its data or to implement part of its logic. So it's better not to spawn one SO per enemy. You spawn enemy as prefab and in their prefab you may add one or more SO to achieve composition. To understand this I can explain the history of the SO, so you can find all the usual implementations. Phase 1 - Data Container Initially SO was made to store (non mutable) data. They could work as TEMPLATES. IE, you have one Weapon SO and you instantiate it one for each weapon. In this way you can just attach the weapon to an unit. public class Attacker : MonoBehaviour { public Weapon weapon; public void Attack(IDamageGetter target) => tar
Cites Stanley · 2019-10 · Stack Overflow · on “How can I pass timer information from my main scene to another(Try Again) scene? Unity C#”
@Roberto Hmm, havent heard about that solution, that would be great if it worked. here is the link anyway, thanks for the discussion! :) [this video]