• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Antony-Blackett · Jun 14, 2011 at 12:17 AM · animationrecord

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Bunny83 · Jun 14, 2011 at 03:48 AM

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 :D 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 :D 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 ;)

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Jun 14, 2011 at 03:50 AM 0
Share

Btw: there's also a "SetAutoRecord$$anonymous$$ode" function. If you want to enable/disable the record mode.

avatar image Antony-Blackett · Jun 14, 2011 at 04:08 AM 0
Share

Thanks a bunch. Yeah I was going to go about it this way myself. But your code will be put to good use. Thanks again.

avatar image dragonikus · Jun 19, 2012 at 04:26 AM 0
Share

Hi, Bunny83! Can You explain where i must use this code, that he began to work? Thanks!

avatar image Bunny83 · Jun 19, 2012 at 06:03 PM 0
Share

@dragonikus: $$anonymous$$y answer actually answers his alternative question:

Or is there a way to check if the editor is in animation record mode so i can disable my component from code?

You don't have to use this anywhere ;) It just tells you if the Animation window of the editor is in autorecord mode or not. It can of course only be used in an editor script. It seems he implemented some additional edit-features for his own stuff and needed to know when the auto-record mode is active to disable his editor script so it doesn't get messed up with the animation recording.

avatar image Bunny83 · Sep 15, 2012 at 01:50 PM 0
Share

I just found some new functions in the AnimationUtility class. It provides a function to get the animationmode and a function to start or stop the animation mode.

So my "hack" is no longer necessary ;)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How do you add an animation to an imported 3D model? 1 Answer

How to Record or Play an animation backwards 1 Answer

Can the animation editor create local rotational data? 3 Answers

Adding animation clips via script 2 Answers

Is it possible to record animation data as unity format while playing the game? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges