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 ungalyant2 · Sep 21, 2013 at 10:31 AM · animationcurveanimation editorkey-frame animation

Unexpected Animation Curve Functionality

I'm currently trying to implement quite a simple system where I can offset all the keyframes after a particular specified time by a set amount on any given animation on any object that has animations.

The part that I'm struggling with currently is that the functionality of AnimationCurve.RemoveKey(), AnimationCurve.AddKey() and AnimationCurve.MoveKey() don't seem to do at all what they should do. Remove Key and Move Key flat out do not delete the specified Key. By using Move Key, it simply moves the key to the new location, but leaves another key where the old one was. Simply using remove key appears to do nothing. And whilst the new keys and their positions do appear on the animation curve when accessing it through the animation editor, the new keys added through Move Key or Add Key are not in the AnimationCurve.keys array.

Here is my current code (This assumes that curves is a list of AnimationCurves, and curveData is an array of AnimationClipCurveData. Selected Time is the time specified by the user to push all keyframes after back, and pushTime is the amount each keyframe after the specified time is to be push back by):

                     for (int i = 0; i < curves.Count; i++)
                     {
                         AnimationCurve currentCurve = curves[i];
                                                                         
                         for (int j = 0; j < currentCurve.keys.Length; j++)
                         {
                             Keyframe currentKey = currentCurve.keys[j];
                                                         
                             if (currentKey.time > selectedTime)
                             {                                    
                                 currentKey.time += pushTime;
                                                                 
                                 currentCurve.RemoveKey(j);
                                 
                                 if (j >= currentCurve.keys.Length)
                                 {
                                     currentCurve.AddKey(currentKey);
                                 }
                                 else
                                 {
                                     currentCurve.MoveKey(j, currentKey);
                                 }
                                 
                             }
                         }
                         
                         currentState.clip.SetCurve(curveData[i].path, curveData[i].type, curveData[i].propertyName, currentCurve);
                     }

Any help would be appreciated.

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 ungalyant2 · Sep 27, 2013 at 11:50 AM

I have established that in fact, the code was correct, but my issue is due to the fact that when animating transforms (position, rotation and scale) key frames are automatically synchronised together and that is causing keyframes to be left behind even after I have deleted them because they are in synch with other keyframes. I.e. when I delete or move a keyframe that adjusts an object's X position, the new keyframe is created, and the old keyframe is deleted, but a new keyframe is put back where the old keyframe was to be in synch with the keyframe for the Y and Z positions.

Apparently AnimationUtility.GetEditorCurve() is used to counteract this issue, but I have no idea how exactly to utilise it, if anyone were willing to give a more in depth description than the script reference page, that would be incredibly useful.

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

15 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

Related Questions

Can you Record Character Player actions to Keyframing so that can make Cinematic scene? 0 Answers

2d component animation, change sprites in runtime. 0 Answers

Unity 4.3 - 2D Animation - Dope Sheet Not Working!! 2 Answers

Setting keys in Animation Editor through Editor code 0 Answers

Animated objects rotation is flawed. 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