Can you turn off auto keyframe in the animation window?

I have a component on an object that only runs in edit mode. This script helps me align my objects by making them look at a point and does this each frame they are selected so I can move them around easily. I also have added an animation to my object. The problem is that when I scrub my animation the script updates the objects rotation and that automatically gets key framed in the animation.

Is there anyway to turn off auto key framing in the animation window? Or is there a way to check if the editor is in animation record mode so i can disable my component from code?

Well, that’s a very special case. Unfortunately AnimationWindow is an internal class, so you can’t access it directly. The second problem is that you can’t search for the instance of the opened AnimationWindow. The only way i’ve found is that you check EditorWindow.focusedWindow and when you focus the animation window you can “grab” the reference. With reflection you can call the function GetAutoRecordMode of the animation window to get the record state.

This little helper function will only work in Editor scripts and only when the AnimationWindow is focused.

Note: This is a pure hack :smiley: you should avoid such things.

// C#
bool GetAutoRecordMode()
{
    UnityEditor.EditorWindow W = UnityEditor.EditorWindow.focusedWindow;
    System.Type T = W.GetType();
    if (T.Name == "AnimationWindow")
    {   
        System.Object Res = T.InvokeMember("GetAutoRecordMode",System.Reflection.BindingFlags.InvokeMethod,null,W,null);
        return ((bool)Res);
    }
    return false;
}

I have it finally perfect :smiley: The function works always. It search for the animation window and if it’s there it get the record state, otherwise it will return false as well.

bool GetAutoRecordMode()
{
    System.Type T = System.Type.GetType("UnityEditor.AnimationWindow,UnityEditor");
    Object[] allAniWindows = Resources.FindObjectsOfTypeAll(T);
    if (allAniWindows.Length > 0)
    {
        UnityEditor.EditorWindow W = (UnityEditor.EditorWindow)allAniWindows[0];
        System.Object Res = T.InvokeMember("GetAutoRecordMode", System.Reflection.BindingFlags.InvokeMethod, null, W, null);
        return ((bool)Res);
    }
    return false;
}

Thanks to ILSpy i’ve figured out how to “find” an EditorWindow :wink: