Search Unity

Update instance of ScriptableObject w/o it being selected in editor

Discussion in 'Immediate Mode GUI (IMGUI)' started by AntFitch, Sep 15, 2016.

  1. AntFitch

    AntFitch

    Joined:
    Jan 31, 2012
    Posts:
    243
    Whenever I make a change to a field in a scriptable object, the scriptable object instances don't update unless I specifically click them in the Unity Editor.

    Does anyone know of a workaround?

    Thanks!
     
  2. IzzySoft

    IzzySoft

    Joined:
    Feb 11, 2013
    Posts:
    376
    could:
    Code (csharp):
    1.  
    2.   EditorUtility.SetDirty( ScrObj_Instance );
    3.  
    work in this case?
     
  3. AntFitch

    AntFitch

    Joined:
    Jan 31, 2012
    Posts:
    243
    This did the trick:

    Code (CSharp):
    1. // a method attached to button in custom editor.
    2. public void RefreshAllScriptableObjects()
    3. {
    4.     // get all objects in "Assets/Resources/My Objects" directory
    5.    Object[] allObjects = Resources.LoadAll("My Objects/");
    6.  
    7.     // get my objects
    8.     List<MyObject> myObjects = (from t in allObjects select t).OfType<myObject>().ToList();
    9.  
    10.     // refresh all of my objects with the new data
    11.     foreach (MyObject o in myObjects)
    12.     {
    13.         MyProperties.RefreshProperties(o);
    14.         Debug.Log("Properties refreshed for: " + o.name);
    15.     }
    16. }
     
    IzzySoft likes this.