- Home /
When would you use a ScriptableObject?
I have lots of data being pulled off of the internet and stored as a file. Is it better to use a ScriptableObject, and if not what is the use of a ScriptableObject?
Answer by Bunny83 · Nov 01, 2014 at 03:52 PM
If the data is loaded at runtime it's pointless to use ScriptableObjects. A ScriptableObject is useful when you have have data in your project that need to be serialized (with Unity's serialization system) as asset so it's included in the build. At runtime you can't serialize anything with Unity's serialization system. You have to roll your own serialization system, so there's no point in using ScriptableObject.
For example the TerrainData class in Unity is a ScriptableObject that holds the terrain data which is stored as asset in the project so it could be used by multiple Terrains. ScriptableObjects are usually created with editor scripts at edit time.
You can use them as pure data class at runtime, but it's just more complicated since you have to create the instance with CreateInstance instead of "new". In most cases, at runtime, "normal" classes are more convenient.