Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Animator.GetFloat Calls Lag By One Frame

Discussion in 'Animation Rigging' started by ChristopherBKroll, Jul 7, 2023.

  1. ChristopherBKroll

    ChristopherBKroll

    Joined:
    Oct 24, 2022
    Posts:
    4
    When using the Animator component to get animated float parameter values, the values lag by one frame. That is to say that calling Animator.GetFloat will return the float parameter values from the last frame. This can be remedied by moving the Animator.GetFloat call to the LateUpdate stage, however, there is no way to do this when creating a custom RigConstraint with the Animation Rigging Package. Does anyone know of a solution for this. Is there some way to get the float values directly out of the animation stream?

    Here is a sample project that demonstrates the issue.

     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,396
    Maybe change the script execution order for your script?
     
  3. ChristopherBKroll

    ChristopherBKroll

    Joined:
    Oct 24, 2022
    Posts:
    4
    Good suggestion @DevDunk, we did try that. Unfortunately it did not work for two reasons.
    1. No way to control the execution order of the Animator
    2. The pushing of the animated float value back to the Animator Parameter does not happen until LateUpdate, which is too late for custom RigConstraints. It seems there is no way to control the dispatching of the constraint's animation jobs. That seems to be tied to the Update stage.

    Some other things we have tried:
    1. Creating a custom PlayableBehaviour that gets the animated float values and passes them to the RigConstraint. Same issue here. The values obtained are a frame old.
    2. Creating another custom RigConstraint that gets the animated float values and passes them to the rig constraint that animates the mesh. The thinking was that since constraints are evaluated from the top of the hierarchy to the bottom we could place the float grabber higher up to force the correct timing of the values. Again this did not work because the root of the problem is in the Animator.
     
  4. ChristopherBKroll

    ChristopherBKroll

    Joined:
    Oct 24, 2022
    Posts:
    4