Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Using GetCurrentAnimatorStateInfo stops future animation events from being called?

Discussion in 'Animation' started by DarkProphetStudio, Nov 20, 2023.

  1. DarkProphetStudio


    Feb 23, 2019
    I have a script that returns characters to an idle state by triggering a function on a delay time based on

    However, on animation states that have animation events in their timeline, using this method's info seems to completely disregard any animation events beyond the first one in the timeline.
    Stranger still, simply logging or assigning the GetCurrentAnimatorStateInfo to a variable does not do this, only if the data, .length in this case, is used as a function parameter.
    I've tried both these methods with the same result:
    Invoke(nameof(Idle), animator.GetCurrentAnimatorStateInfo(0).length);
    and inside a coroutine:
    return new WaitForSeconds(animator.GetCurrentAnimatorStateInfo(0).length);

    They both stop any further animation events from being called. Is this expected functionality? Is this a bug?
    How to get around it? For now the only solution I see for my use case is to put animation events at the final frame for each animation that needs it. But this is a tedious workaround.

    Any help on this would be great!
  2. Landa-100


    Sep 9, 2018
    What is your original game logic? there are many ways to handle a specific demand by code.