Unity Scriptable Objects Tutorial Updated

September 24, 2020

Unity

Scriptable Objects


Title: Better Data with Scriptable Objects in Unity! (Tutorial)
By: Unity
Youtube – Tutorial
Description: Quick updated rundown by Unity themselves on using Scriptable Objects.


Title: Scriptable Object Unity Documentation
By: Unity
Unity – Documentation
Description: One of the suggested links to follow from the tutorial video that is just the official documentation on scriptable objects.


Title: Making cool stuff with ScriptableObjects
By: Matt Schell
Unity – Blog
Description: Another suggested link to follow from the tutorial video showing some more examples of using scriptable objects.


Overview

I wanted to make a quick reference to this new video as it was just released yesterday (Sep 23, 2020) and I have wanted to explore scriptable objects in Unity and getting recently updated information is always useful.

Scriptable Objects as Data Containers

Scriptable Objects can be useful tools as data containers as is shown in their example using them for cards in a card game. They explain they can be a better option here than a Monobehaviour because Monobehaviours must be attached to a gameobject, where as Scriptable Objects can be used similarly to regular objects in that they do not have this requirement. If data does not belong to an instance, but is more shared amongst game objects, it is better to store it in a scriptable object. This is because when Monobehaviours reference Scriptable Objects they store a reference that points to the scriptable object as opposed to making their own copy of the data.

Scriptable Objects as Enum States

Scriptable Objects can also be used to author extended Enum states. They explain this through an example where they have a Placeable Data scriptable object which has Enum options for their Attack Type and their Target Type. This appears to just mean they support Enum lists which then allow for an easy dropdown option in the Inspector (similar to how Enums generally work in my experience).

Runtime Data Editing

They expand on the benefits of using scriptable objects as extended Enum states is that they allow for real time data editing (while in play mode). Normally most edits made in the Unity Editor during play mode are not saved so you have to remember them and reapply them if they are changes you want. Scriptable objects however can have their edits during play mode saved on the spot so they will persist even after leaving play mode. This is because scriptable objects are not bound to a scene’s runtime, they exist on a project basis in the Assets folder.