Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Undo.RecordObject() not working with AnimationCurves ?

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

  1. AlbinosMou


    Mar 6, 2015
    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):
    2.     MyScript script = target as MyScript;
    4.     EditorGUI.BeginChangeCheck();
    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);
    10.     if(EditorGUI.EndChangeCheck ())
    11.     {
    12.         Undo.RecordObject(script, "Simple Tweak : " +;
    13.         script.myCurve = new AnimationCurve(myCurve.keys);
    14.         script.firstFloat = firstFloat;
    15.         script.secondFloat = secondFloat;
    16.         EditorUtility.SetDirty(script);
    17.     }
    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


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


    Mar 6, 2015
    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?