Search code examples
unity-game-engineeditorscriptable-object

Unity: How To Assign ScriptableObject Instance In Editor Code


Want to access ScriptableObject data from an editor code, namely a custom Node Graph Editor code:

  1. Create a ScriptableObject containing Color field.

  2. Create an instance of that SO and set the Color in the inspector.

  3. Acquire that SO instance from an editor script.(if this was a Monobehavior we could drag drop into a SerializeField, how to achieve this from an editor script?)

  4. Use the color from SO instance.


Solution

  • You can use :

    SO SOInstance = Resources.Load("PATH_OF_YOUR_SO");

    https://docs.unity3d.com/ScriptReference/Resources.Load.html