Search Unity

Resolved Frame discrepancy between code and animation

Discussion in 'Animation' started by Nickjh82, Jun 9, 2020.

  1. Nickjh82

    Nickjh82

    Joined:
    Mar 30, 2020
    Posts:
    11
    Hey folks, I'm having an issue that I'm finding difficult to communicate. It's essentially the animator not lining up with code, and being a frame out. Similar in description to the following posts.

    https://answers.unity.com/questions/651201/mecanim-1-frame-delay.html
    https://forum.unity.com/threads/mecanim-animator-1-frame-lag.247450/

    What's happening is, as my player is hitting a wall the character is flipping via code on one frame, then on the following frame the animation kicks in, instead of them both lining up. In the video clip below you can see the first two jumps the animation glitches, but on the third it's fine.



    I've also found something strange that might just be a red herring from the inspector but my animation script pulls from the collision script to detect if the bool is true or not, then sets the parameter in the animator. Except, it's pulled the results from the collision script before the collision script itself has got them.... see two images below. -

    Frame 1:
    https://ibb.co/Ht0PGwR

    Frame 2 (following frame):
    https://ibb.co/w0NBXq5

    Image 1: Code Flips, setbools set, collisions not updated, animation doesn't change.
    Image 2 following frame: Animation kicks in the next frame and everything is correct. Just a frame too late after the code flip.

    Some things I've tried (that I can remember!):
    1. Moving Flip code and set bools to different places between update, fixedupdate, lateupdate.
    2. Moving the flip code and the animation setbool next to each other in the same script.
    3. Changing the script execution order.
    4. Changing my collision detections from OverlapCircles to Collider2D.cast.
    5. Moving the animator from the child object to the parent object
    6. Changing my flip method from spriterender.flipx to transform.rotate.
    7. Stripping the player script to just the essentials and using different sprites/animations.
    8. I have Animation script, collision script and player controller script. I've tried move the scripts into a single script.
    9. All animation transitions are set to 0 exit time, 0 transition time and both unticked.
    10. Reverting from New Input system back to old.
    11. Stress ball and coffee.

    Any help or guidance where I should be looking will be greatly appreciated.

    EDIT: I wish I could say I fixed this, but I reluctantly just started a fresh project and loaded the same scripts in and it seems okay for now! No idea what this issue was.
     
    Last edited: Jun 9, 2020