Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

AnimatorStateInfo.length is infinity.

Discussion in 'Animation' started by Gibbster2, Oct 7, 2015.

  1. Gibbster2

    Gibbster2

    Joined:
    Jun 15, 2015
    Posts:
    14
    The 'length' field returned from GetCurrentAnimatorStateInfo and GetNextAnimatorStateInfo appears to be infinity. This was working in 5.1.1 and seems to be broken in 5.1.3.
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,228
  3. Gibbster2

    Gibbster2

    Joined:
    Jun 15, 2015
    Posts:
    14
    Awesome. :(
    I've got a demo to show in a week or so. When's the patch coming?
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,228
    Its not fixed yet so don't hold out for the patch. Can you roll back to 5.1.1?
     
  5. Gibbster2

    Gibbster2

    Joined:
    Jun 15, 2015
    Posts:
    14
    Shame. No, we can't roll back unfortunately. I'll get round the problem another way.
     
  6. zead

    zead

    Joined:
    Nov 9, 2014
    Posts:
    4
    I also got this problem.
    It seems to be fixed in Unity 5.2.1 (also working in 5.2.1p4)

    But there is some tiny changes in "AnimatorStateInfo.length"
    In my game i need to pause my animations. i'm doing that by setting the animator speed to 0. But after that i've got AnimatorStateInfo.length returning infinity. I assume that now, the time is inversed scale by the speed.

    i managed to get my projet running again by using "AnimatorStateInfo.GetCurrentAnimatorClipInfo(0)[0].clip.length";
    Since i only got 1 clip in my state that was easy.

    But if you got a more complicated animation state, you should use the weight info to compute the real time.
     
  7. Gibbster2

    Gibbster2

    Joined:
    Jun 15, 2015
    Posts:
    14
    This appears to be still broken. Seems to work when requesting layer 0, but not layer 1.
    I'm using Unity 5.3.1p3.
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,228
    May be worth trying the latest version 5.3.4px. If its still not working please file a bug report and post the number here. I'll make sure it goes to the right person
     
  9. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    it expected to get a length of infinity if:
    1. set animator speed to 0.
    2. set animation state speed to 0.
    3. set animation state speed multiplier to 0.
     
    karl_jones likes this.
  10. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Did anyone verify if this is fixed in the latest 5.3.4 patch, or the 5.4 beta? It's broken in 5.3.2f1.
     
  11. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    if it's broken please log a bug, we are not aware of all issues
     
  12. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    Oh I thought it was already known and logged, and fixed in a 5.3.4 patch release. I'll reproduce it tomorrow morning and log a bug. Thanks.
     
  13. Gibbster2

    Gibbster2

    Joined:
    Jun 15, 2015
    Posts:
    14
    Sorry to be a scratched record but this is still broken. Couldn't find an associated bug for it.
    It's not working if the animation is blending.
     
  14. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    I never got around to logging a bug - I just worked around it.
     
  15. Gibbster2

    Gibbster2

    Joined:
    Jun 15, 2015
    Posts:
    14
    Can't work around this one, I'm afraid. I need to know the length of the anim so I can slow it down/speed it up to match a specific time.
    Can't seem to find an 'Add new issue' button on the issue tracker page either. Not my day. :(
     
  16. Gibbster2

    Gibbster2

    Joined:
    Jun 15, 2015
    Posts:
    14
    Is this a relatively new thing?

    Alternatively, is there a way of getting the length of the state before it start's playing? i.e. once I've set the appropriate anim parameters for a blend tree, can I query the length of the clip it's going to play? I have anims that need speeding up depending on how quickly you attack so I need to set the playback speed parameter to make the anim play over a set time. I was doing this by setting the parameter to 0 (so it didn't progress past frame 0) and once it's playing I can set it to match the time. This no longer works.
     
  17. samizzo

    samizzo

    Joined:
    Sep 7, 2011
    Posts:
    487
    That normalising behaviour is annoying. Is it actually useful? I just want to know the length regardless of what speed is set to. If the speed is 2 it just means we get to the end quicker but the length should still be the same!
     
  18. nanom

    nanom

    Joined:
    Jun 21, 2017
    Posts:
    1
    hm, i think the problem can be solved by:

    Code (CSharp):
    1. yield return new WaitForEndOfFrame();
    After that, this line will return right value:

    Code (CSharp):
    1. animTime = GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).length;
    If anyone cares )