Scriptable Objects
Last modified by Maarten Struijk Wilbrink on 2024/09/11 14:24
Getting Started
Scriptable Objects are fantastic tools, in the right circumstances. They are little assets that live inside the Projects folder. This allows you to easily reference them from one or multiple places, and is a great way to make sure that data or code is only expressed once in your project.
Tips and Tricks
A quirk of SOs is that you can change the data in them during Playmode, which then persist. This can be great when trying to figure out the correct setting.
Caveats
- In a Build of your Project, changes to data in your SOs don’t normally persist across Scene changes. If you want to do this, you should either work with Additive scenes (recommended approach), or store the affected SOs in a List which is on a DoNotDestroyOnLoad GameObject.
- Custom Events with Unity Event extensions do not normally pass their extension data across Scene changes. Again, using Additive scenes may help here.
- When using the SO Events approach mentioned below, stay mindful of the number of Events you’re creating. This can quickly become overwhelming.
Resources
SO Basics
SO Variables && Events: Ryan Hipple Unity 2017 talk