Search Unity

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. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    507
    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. :)
     
  4. Diesign

    Diesign

    Joined:
    May 15, 2016
    Posts:
    16
    @Kybernetik woah so we can't modify a single keyframe of an animation curve at runtime unless that keyframe has already been set as a variable in the editor?
     
  5. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    507
    Probably not even that. As I said, AnimationClip.SetCurve might work.