Search Unity

How to set dirty a class from an interface

Discussion in 'Editor & General Support' started by konsnos, Sep 5, 2016.

  1. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    121
    Hey all,

    I'm editing some variables inside a class and I have created an interface in order to edit variables in a generic way. However it seems that EditorUtility.SetDirty doesn't work without the specific instance of the class so I can't apply the new values.

    Is there a way to do this or do I have to try every class it implements that interface?
     
  2. konsnos

    konsnos

    Joined:
    Feb 13, 2012
    Posts:
    121
    I decided to change my code structure to use ScriptableObject instead, so I solved it like that.
     
  3. mitaywalle

    mitaywalle

    Joined:
    Jul 1, 2013
    Posts:
    253
    Hi, if someone still searching for answer.

    If your Interface is inherited from MonoBehaviour, you can make like this:

    Code (CSharp):
    1. EditorUtility.SetDirty(InterfaceObject as MonoBehaviour);
     
    KinanGH likes this.