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 Spidyy · Aug 28, 2013 at 04:01 PM · moveanimationcurvekeyframe

How AnimationCurve.MoveKey works?

Hey there.

I'm writing a timeline editor, using AnimationCurves, and in this editor, I want to be able to move the keyframes over time. I could use the default AnimationCurve editor, but I need to have a view of the timeline's range for all keyframes of all curves at a same time to be able to sync different curves together.

One way to move a keyframe within the time is by deleting it and adding it with its new time, but it is what the function MoveKey specificaly do.

BUT, while using it, it delete some keyframes without adding them, and I don't understand the return value.

The documentation is also reaaaally minimalist, without example or whatsoever : http://docs.unity3d.com/Documentation/ScriptReference/AnimationCurve.MoveKey.html

So, does anyone here understood the way one can move a keyframe safely? (and in another way, multiple keyframes alltogether?)

 public AnimationCurve curve;
                                 
 // ...
                         
 for(int key = 0; key < curve.length; key++)
 {
     Keyframe temp = curve[key];
     temp.time = GetNewTime();
     curve.MoveKey(key, temp);
 }
Comment
Add comment · Show 2
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 Sajidfarooq · Aug 28, 2013 at 04:09 PM 0
Share

Is this for the Editor, or in-game?

avatar image Spidyy · Aug 29, 2013 at 12:10 AM 0
Share

Editor exclusively.

I'm trying to set the time of multiple keyframes at a time.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Aug 28, 2013 at 05:04 PM

An AnimationCurve has to order all it's keyframes by the keyframes time. If you change the time of a keyframe to a value of another keyframe those keyframes will be "merged" since it's not possible to have two keyframes at the exact same time.

I never used MoveKey, but from the description it seems it takes care of the sorting and merge the keyframe with another one if they share the same time.

The function should in any case return the new index of the keyframe.

Your for loop is a bit of a risk since MoveKey can change the order of the array. You should use the keys property instead.

store a local copy of your keyframes, change them as you like and assign them back. When you assign the temp array back the keyframes will be sorted automatically.

Comment
Add comment · Show 1 · 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 Spidyy · Aug 28, 2013 at 07:01 PM 0
Share

And what about the returned index? It sometimes return -1.

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

17 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

Related Questions

How can I set the tangents of Keyframes in an AnimationCurve through scripting? 1 Answer

Tangents ignored while setting keyframes 1 Answer

Move a keyframe in time only 1 Answer

How can I make an animation curve Keyframe "Auto" in code? 3 Answers

Accessing Animation Curves/Keyframes during runtime 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