Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

How to dynamically set animation key frame value?

Discussion in 'Animation' started by VElysianP, Feb 10, 2019.

  1. VElysianP

    VElysianP

    Joined:
    Jul 24, 2018
    Posts:
    2
    I created animation clips like the image shown below, but I need to revise the Position.y value dynamically by script. Therefore I am wondering if there is a method for me to revise the Position.y value. Thank you very much.
    upload_2019-2-10_17-38-12.png
     
  2. SilentSin

    SilentSin

    Joined:
    Jan 3, 2013
    Posts:
    264
    In the editor, you can use the UnityEditor.AnimationUtility class to get access to the curves of an AnimationClip and modify their keyframes however you like.

    At runtime, you can't. AnimationClip.SetCurve might work, but there is no GetCurve so you can't just modify a single keyframe of an existing curve unless you get it in the editor and serialize it separately from the clip.

    I would just use a script to control the object instead. That way you get full control.
     
  3. VElysianP

    VElysianP

    Joined:
    Jul 24, 2018
    Posts:
    2
    Thanks a lot! I know there are ways to edit the curve, but this is not the function I want. I will switch to controlling the object instead. :)