Search Unity

Undo.RecordObject() not working with AnimationCurves ?

Discussion in 'Immediate Mode GUI (IMGUI)' started by AlbinosMou, Mar 6, 2015.

  1. AlbinosMou

    AlbinosMou

    Joined:
    Mar 6, 2015
    Posts:
    28
    Hi !

    I am currently doing a custom Inspector for my script, and I want to handle all the undo-related features, just as it works in the default Inspector.

    So, in my Editor Script (in OnInspectorGUI) I use the following code :

    Code (CSharp):
    1.  
    2.     MyScript script = target as MyScript;
    3.          
    4.     EditorGUI.BeginChangeCheck();
    5.  
    6.     AnimationCurve myCurve = EditorGUILayout.CurveField("My Curve", script.myCurve);
    7.     float firstFloat = EditorGUILayout.FloatField("First Float", script.firstFloat);
    8.     float secondFloat = EditorGUILayout.FloatField("Second Float", script.secondFloat);
    9.  
    10.     if(EditorGUI.EndChangeCheck ())
    11.     {
    12.         Undo.RecordObject(script, "Simple Tweak : " + script.name);
    13.         script.myCurve = new AnimationCurve(myCurve.keys);
    14.         script.firstFloat = firstFloat;
    15.         script.secondFloat = secondFloat;
    16.         EditorUtility.SetDirty(script);
    17.     }
    18.  
    Everything works just fine. My values are updated and I can even undo the changes done to my two floats. But when it comes to editing my AnimationCurve, RecordObject() doesn't seem to be called, even though EditorGUI.EndChangeCheck() does return true (I tried to Debug.Log something and it worked).

    So, is there something more I should do, or is it just that the AnimationCurves are not undoable ? That wouldn't make much sense since the Undo works well from a default Inspector.

    Thank you in advance !
     
    Last edited: Mar 9, 2015
  2. Zephyr62

    Zephyr62

    Joined:
    Jan 17, 2019
    Posts:
    1
    Any updates to this problem? Im currently facing the same issue
     
  3. AlbinosMou

    AlbinosMou

    Joined:
    Mar 6, 2015
    Posts:
    28
    Well this was eight years ago so to be honest I don't really remember it ):
    The first thing that would come to my mind is that AnimationCurves use a separate window for editing, which makes the Inspector lose focus, so if this problem still exists it must have something to do with this issue.

    If the Undo feature works properly from a default inspector, it might be a better practice to edit and save the serializedObject through its SerializedProperty members then calling serializedObject.ApplyModifiedProperties() without resorting to the Undo class. Would that help with your issue?