Unity ScriptableObjects

3 min. read

Scriptable Objects

Introduction

A class you can derive from if you want to create objects that don’t need to be attached to game objects. allow you to create objects which are assets which can either hold custom data or execute code

Examples

One example would be to create a custom asset that holds all the statistics for a given enemy type. Say you want to change the maximum speed of all those enemies. You could simply edit a single value on our ScriptableObject asset, as opposed to having those values stored in the public fields of a MonoBehaviour attached to an enemy prefab or prefabs. This can help with both the centralization of data and version control. These values also persist after being changed in play mode, since we are changing a value on an asset.

Another way that we can use them is to create assets which hold executable code. An example of this is seen in the video series below showing the Pluggable AI System. All of the pieces of code which compose the AI behavior are stored in ScriptableObject assets, which you can then configure and combine in the Inspector, without writing additional code.

One of the use cases that Richard demonstrates in this talk is a pluggable AI system with different ‘brains’ that can be plugged into AI tanks

References

Unity - ScriptableObjects

https://baraujo.net/unity3d-making-singletons-from-scriptableobjects-automatically/

Saving Data in Unity: ScriptableObjects

SCRIPTABLE OBJECTS in Unity

Scriptable Objects: What are they? How do you use them?

http://wiki.unity3d.com/index.php?title=CreateScriptableObjectAsset

https://learn.unity.com/tutorial/introduction-to-scriptable-objects

https://docs.unity3d.com/Manual/class-ScriptableObject.html

https://blog.unity.com/technology/making-cool-stuff-with-scriptableobjects

https://github.com/ciro-unity/UnityRoyale-Public

How to use Unity’s Addressable Asset system for speed and performance - Unite LA

Blending gameplay and storytelling with Timeline: 2019 Improvements - Unity at GDC 2019

Unity blog link

Overthrowing the MonoBehaviour Tyranny In a Glorious Scriptable Object Revolution
https://www.youtube.com/watch?v=6vmRwLYWNRo

Pluggable AI
https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/scriptable-objects

Text Adventure
https://unity3d.com/learn/tutorials/topics/scripting/introduction-and-goals

Game Architecture with Scriptable Objects
https://www.youtube.com/watch?v=raQ3iHhE_Kk