Search Unity

get time of animation clip in Animation(legacy) component?

Discussion in 'Animation' started by FeastSC2, Nov 1, 2018.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    I would like to get the playtime of an animation clip, this way I can stop playing the animation then restart it at a later time when I'm unpausing the game.

    I mean the animation clip used by an Animation(legacy) component and not an Animator.

    How can I access that information?
     
  2. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    Does no one know this?
     
  3. All animation should stop if you pull Time.timeScale to 0 and should continue when you put back the original value.
    Also you can pause if you set the individual animation.enable = false; and should continue when you set it true.

    Does any of these work for you?

    BTW: animation.clip.length;
    https://docs.unity3d.com/ScriptReference/AnimationClip-length.html
     
  4. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978
    Time.timescale doesn't work and animation.enable sets the animation back to the start. The length was to get how long the whole animation lasts and not where it's at in that animation.

    So I still don't know how to do it.. ;s
     
  5. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    978

    That works great, thanks! AnimationState has all the interesting information. Time.timeScale set to 0 does not stop the animation but that's a good thing because then animation on UI would be stopped when the game is paused. If it's a bug it's a good one.