Search Unity

How do I get the current time of animation clip?

Discussion in 'Animation' started by MilanGM, Jul 14, 2015.

  1. MilanGM

    MilanGM

    Joined:
    Nov 20, 2013
    Posts:
    8
    I am creating 2D animations on some game objects, and all they got is Animator component when I create those animations, I don't have access to Animation component.

    So... how do I get the current time of currently playing animation clip?
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,698
  3. MilanGM

    MilanGM

    Joined:
    Nov 20, 2013
    Posts:
    8
    Yea, I've tried that... But length returns some wrong values. For example, i have 2 animations first of length 3 sec. and second of length 1 sec. and when i play first animation it prints "1" as length, and when i play a second animation, first time it prints "4" and second time "2" (?!?)
     
  4. MilanGM

    MilanGM

    Joined:
    Nov 20, 2013
    Posts:
    8
  5. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,698
    Does Animator.GetCurrentAnimatorClipInfo() work better? It returns an array of animation clips, since a state can be playing multiple clips in a blend. If you know your state only has one clip, you can just look at the length property of first element in the array.

    Animator controller layers are different from physics layers (the actual layers in Unity that have a 32 limit). Animator controller layers allow you to play animations on top of other animations. The typical example is a full body animation on layer 0 (e.g., walking) and an upper body animation on layer 1 (e.g., waving). This allows you to generate a walking-while-waving animation without having to actually prepare it as a separate, single animation clip.
     
  6. MilanGM

    MilanGM

    Joined:
    Nov 20, 2013
    Posts:
    8
    Thanks a lot for your help!