Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 andsee · Sep 04, 2014 at 12:03 PM · animationanimationcurve

How to create animations via script.

I've created an animation clip and saved it out but when I then drag it to the object to animate I get yellow parameters shown in the animation window. Clicking on them selects the object that should be animated, but the animation does not drive the object (in play or edit mode). You can see in the screenshot that the current time is set to 0:22 and yet the values shown next to the properties on the left all read 0.

Any ideas? Anyone know what the yellow properties indicate, they are usually white / grey.

Code to create Assets/Test.anim

 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 public class TestAnim : Editor
 {
     [UnityEditor.MenuItem("TestAnim/Create Test")]
     public static void CreateAnim ()
     {
         AnimationClip clip = new AnimationClip();
 
         clip.SetCurve("", typeof(Transform), "position.x", AnimationCurve.EaseInOut(0, 0, 2, 10));
         clip.SetCurve("", typeof(Transform), "position.y", AnimationCurve.EaseInOut(0, 10, 2, 0));
         clip.SetCurve("", typeof(Transform), "position.z", AnimationCurve.EaseInOut(0, 5, 2, 2));
 
         AssetDatabase.CreateAsset(clip, "Assets/Test.anim");
     }    
 }
 

alt text

capture.png (22.7 kB)
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 GameVortex · Sep 04, 2014 at 12:32 PM

Not sure why they are yellow. In my editor they turn Red, indicating that the values cannot be found. Try using "localPosition.x" instead as indicated by the documentation for SetCurve.

Comment
Add comment · Show 2 · 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 andsee · Sep 04, 2014 at 01:21 PM 0
Share

Yep that works thanks.

Also found

         AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve("", typeof(Transform), "m_LocalPosition.x"), AnimationCurve.EaseInOut(0, 0, 2, 10));

Can't seem to set the Euler Editor curves though via

     AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve("", typeof(Transform), "localEulerAnglesBaked.z"), AnimationCurve.EaseInOut(0, 5, 2, 2));

avatar image andsee · Sep 04, 2014 at 01:43 PM 0
Share

Finally.

         AnimationUtility.SetEditorCurve(clip, EditorCurveBinding.FloatCurve("", typeof(Transform), "localEulerAnglesBaked.z"), AnimationCurve.EaseInOut(0, 5, 2, 2));

was not working because I was only specifying one component (z), since that's all I'm animating. If I also set x and y to 0 the Euler rotations appear in the animation and drive the transform.

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

23 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

Related Questions

Field of view scripted animation curve 1 Answer

Modifying an entire animation with a single animation curve? 1 Answer

Way to have mulitple input? 1 Answer

I try'd so hard, but my animation script doesnt work..? 1 Answer

Which is better: script or animation (which needs to change with scripting)? 1 Answer


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