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 nicktringali · Dec 05, 2015 at 06:18 PM · timeanimationcurvekeyframe

Edit Keyframe of Animation Curve

I have an Animation Curve defined in the inspector for some float interpolation, and I'd like to then edit some of the Keyframe's properties at runtime. However, something like

 Curve1.keys[0].time = 5f;

seems to do nothing to affect the Keyframe. The best I can do is copy the Keyframe array, adjust it separately, and then reassign it back to the Curve. Am I missing something that would let me edit the variables as I need them?

Thanks!

Comment
Add comment · Show 1
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 TheNoobieWaffle · Aug 13, 2017 at 10:51 AM 0
Share

Add$$anonymous$$eyframe() should honestly have a bool parameter to allow (or disallow) overwriting the keyframe with the same time. Its stupid to have to jump through hoops to do something so simple.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by JonathanCzeck · Dec 05, 2015 at 09:14 PM

The reason that does not work is because Keyframe is a struct, a value type. In UnityScript aka JavaScript they do work behind the scenes so it works. In C# you do it manually:

 KeyFrame[] keys = Curve1.keys; // Know that this is making a copy of all keys
 Keyframe keyFrame = keys[0];
 keyFrame.time = 5f;
 keys[0] = keyframe;
 Curve1.keys = keys; // This is copying the keys back into the AnimationCurve's array.
 
 

(Untested)

Comment
Add comment · Show 3 · 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 · Dec 05, 2015 at 10:49 PM 2
Share

There's no need to copy a keyframe into a local variable. You can access struct members fine inside an array. The problem is the property which returns a copy of the internally used array. The actual array sits on the native code side. Whenever you "read" the keys property a managed array is created and filled with the keyframes. You have to call the setter of the keys property to apply the changes. So this is enough:

 $$anonymous$$eyFrame[] keys = Curve1.keys; // Get a copy of the array
 keys[0].time = 5f;
 Curve1.keys = keys; // assign the array back to the property

For things like that it would be better if UT would remove properties like that and provide Get and Set methods since that would be more intuitive. It's the same with the $$anonymous$$esh class.

avatar image nicktringali Bunny83 · Dec 06, 2015 at 03:03 AM 0
Share

Yeah, I had arrived at the same conclusion. For the moment I can write my own Set() for Curves and go from there.

avatar image BillM135 Bunny83 · Jun 22, 2018 at 10:59 PM 0
Share

Thank you , it worked!

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

7 People are following this question.

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

Related Questions

Accessing Animation Curves/Keyframes during runtime 1 Answer

key count: 1 on curve 'curvename' error 1 Answer

get key in animation curve 0 Answers

Animation Window: How to scale keyframes to increase time? 9 Answers

How does inTangent and outTangent in a KeyFrame work? 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