🎌

Scriptable Objects Notes

scriptable objects only get callbacks of:

  • onEnable()
  • onDisable()
  • onDestroy()

define it as:

public class MyScritableObject : UnityEngine.ScritableObject
{
	public int someVar;
}

then to access it in your code — it is a literal:

public MyScriptableObject MyScritableObjectInstance;

A lot of the tutorials and videos are from 2016 and before — so I'm getting conflicting information about how they work.

You can create in memory:

ScritableObject.CreateInstance<MyScriptableObject>();

You can bind them to asset files:

AssetDatabase.CreateAsset()

AssetDatabase.AddObjectToAsset()

Use [CreateAssetMenu] to decorator to make it show up in Create in Unity.

Things to use Scritable Objects:

  • use it as a data object and table
  • you can use propertyDrawers and custom editors in inspector
  • This lets you replace the need for "database" in your project.
  • And it lets you edit them in place.

Empty scritable objects:

  • You can create scriptable objects like an emum so that people in unity can just add a new enum easily in the editor
  • image

Dual Serialisation (includes support JsonUtility)

https://www.youtube.com/watch?v=6vmRwLYWNRo