Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Help on GUI.Changed(), Serialized properties and Undo

Discussion in 'Immediate Mode GUI (IMGUI)' started by Stephan-B, Oct 30, 2013.

  1. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    In a custom editor, I have several serialized properties. As expect when I change any of them, GUI.Changed is set to true.

    However, if I undo a change, the value(s) for whatever serialized property was changed is reflected in the custom editor but as this value is changed, the GUI.Changed is never set. How do I detect when a value in a serialized property has been changed as a result of an undo operation?

    I thought serialized properties handled that automatically... what am i missing here?
     
  2. dkozar

    dkozar

    Joined:
    Nov 30, 2009
    Posts:
    1,410
    You should really check out the CatlikeCoding tutorials on this subject:

    http://catlikecoding.com/unity/tutorials/editor/star/
    http://catlikecoding.com/unity/tutorials/editor/custom-data/

    It's related to BeginProperty method:

    Code (csharp):
    1. label = EditorGUI.BeginProperty(position, label, property);
    2. EditorGUI.Foldout(foldoutPosition, property.isExpanded, label, true);
    3. EditorGUI.EndProperty();
    Cheers,
     
    ProbePLayer likes this.
  3. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    CatLikeCoding does have good tutorials but that is not the issue I am having.

    What I am describing is whenever an Undo / Redo is performed, other than checking for Event.current.commandName to see if it matches "UndoRedoPerformed", there isn't anyway (that I know) of detecting that an Undo / Redo was performed which affected some serialized property.

    Unless, I am missing something, it seems that whenever an Undo / Redo is performed on some serialized fields / properties, it should set GUI.changed = true to make it easier to detect whenever it occurs.

    P.S. CatLikeCoding did use this technique in one of his tutorials but having to do this seems a round about way to get there.
     
  4. wedgiebee

    wedgiebee

    Joined:
    Aug 9, 2016
    Posts:
    40

    Ten year anniversary of this thread but I am struggling with this same thing! Any updates/suggestions?