Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Question about animator Force Update with deltaTime 0

Discussion in 'Animation Rigging' started by Octanas, Apr 17, 2021.

  1. Octanas

    Octanas

    Joined:
    Feb 11, 2021
    Posts:
    1
    I decided to use the Animator has the main state manager for my player character. Basically, in the player script, I always check the Animator's current state to see if an action can be done. Also, the characters movement is done using Root Motion, and the Update Method for the animator is set to Animate Physics.

    However, I've recently ran into a problem that I'm not sure I've solved the correct way. On a TriggerEnter from the player, I set a trigger on the Animator to transition to another state. But it seems like the Animator doesn't start the transition immediately, because in the next FixedUpdate call the transition isn't occurring yet, and consequently the player is still in the previous state and thus some actions that I don't want it to perform are performed.

    To correct this, I call animator.Update(0f) right after setting the trigger, and it ultimately works. When FixedUpdate is called right after that, the transition is occurring, like expected.

    Now, my question is the following: is this a safe solution? By setting the Update function's parameter (deltaTime) to 0, does it simply verify conditions and start transitions, or does it simulate any animation at all?

    Also, is this too expensive? Is there a better solution?