Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by _methotec_ · Sep 20, 2015 at 11:51 AM · animationeditor-scriptingmecanim

How to add Animation Curves on Imported Clips by Script

How can I add a new created AnimationCurve to an AnimationClip by Script?

This is about the float curves that update Animator Parameters with identical names. I can do this by Hand using the Animations tab of the Animation Import Settings.

Unity Documentation: Animation Curves on Imported Clips

But for an InspectorTool on a StateMachineBehaviour I would need to add and edit new curves by script (and edit existing ones).

I have been able to get all existing curves of the used animation clip. Unfortunately I didn't find a possibility to distinguish between the normal bone animation curves and the parameter curves. Luckily I could work around this by checking their names.

When I add a Curve to the animationClip it is in the complete list - so obviously that works. But I want to add a Parameter Curve...

Anyone an Idea?

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
0
Best Answer

Answer by _methotec_ · Sep 22, 2015 at 12:10 PM

After some time with IL-Spy I finally got it working like this:

The Parameter AnimationCurves are stored into the metafiles of the imported FBX files - so to get the changes permanently it is necessary to work with the SerializedProperty m_ClipAnimations of the Modelimporter.

I needed this in a CustomInspector of a StateMachineBehaviour - If you don't skip Step 1.

  1. Get the used AnimationClip of the inspected StateMachineBehaviour with Unitys StateMachineBehaviourContext

  2. Get the instance of the used ModelImporter for that AnimationClip and create the SerializedObject of it.

  3. Now this is the SerializedProperty of the AnimationClip used by this StateMachineBehaviour - to get the Parameter driving AnimationCurves search for the property "curves".

      protected StateMachineBehaviour m_behaviour;
         protected StateMachineBehaviourContext[] m_context;
         protected AnimatorController m_animController;
         protected string m_assetPath;
         protected AnimationClip m_clip;
         protected ModelImporter m_importer;
         protected SerializedObject m_importerSObj;
     
     public virtual void OnEnable()
         {
             // STEP 1
             m_behaviour = target as StateMachineBehaviour;
             m_context = AnimatorController.FindStateMachineBehaviourContext(m_behaviour);
             m_context = AnimatorController.FindStateMachineBehaviourContext(m_behaviour);
             if (m_context != null)
             {
                 // animatorObject can be an AnimatorState or AnimatorStateMachine
                 m_animController = m_context[0].animatorController;
                 AnimatorState state = m_context[0].animatorObject as AnimatorState;
                 if (state != null)
                 {
                     m_clip = state.motion as AnimationClip;
                     if (m_clip != null)
                     {
                         // STEP 2
                         m_assetPath = AssetDatabase.GetAssetPath(m_clip);
                         m_importer = (ModelImporter)AssetImporter.GetAtPath(m_assetPath);
                         m_importerSObj = new SerializedObject(m_importer);
                         SerializedProperty clipProp = m_importerSObj.FindProperty("m_ClipAnimations");
                         for (int i = 0; i < m_importer.clipAnimations.Length; i++)
                         {
                             if (m_clip.name == m_importer.clipAnimations[i].name)
                             {
                                //STEP 3
                                clipProp.GetArrayElementAtIndex(i); // the AnimationClip Property
    
                             }
                         }
                     }
                 }
             }
         }
    
    
    
Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

31 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Issue with a Mecanim motion reference in synchronized layers 0 Answers

Mecanim Tutorial lacking animation? 1 Answer

How can I give variation to animation curve in Unity? (Raw mocap data) 0 Answers

Mecanim not updating script when it switches state? 2 Answers

RootMotion is not Working ... 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