Search Unity

Latency using Mecanim/Animator vs Legacy Animation

Discussion in 'Animation' started by kemijo, Nov 24, 2016.

  1. kemijo

    kemijo

    Joined:
    Apr 7, 2014
    Posts:
    18
    Hey all, Unity newbie here.

    I have a timing based game where an animation plays on user input. The time between receiving input and the animation playing using Mecanim is noticeably laggy compared to Legacy animation or even physics. The manual states that Mecanim is slower than Legacy when using a single state, but for my needs its just way too delayed to be usable.

    I've attached a quick test using 3 cubes that move on vertical input. Feel free to import package into an empty project. From the left, the first uses physics, the second is an FBX cube rigged with 3 joints set to use legacy animation, and the third is a copy of the rig set to use Mecanim with two states (idle and cubeBounce). Physics and legacy are both acceptably responsive. The Mecanim almost always lags behind (it matches the speed of the legacy setup approx 15% or 20% of the time).

    My target is iOS and my dev machine is a 2008 Mac Pro. Testing has been mostly on the Mac (I had the physics setup running on my iPhone and it was fine). The test file was made with Unity 5.4.

    For anyone that has time to test this, please let me know if there is a better way to do this. In my actual game my animations are somewhat more complicated (human skeleton) so I'd like to use Mecanim if possible! Is there any way to make it respond faster?

    Thanks in advance for any and all insights!
     

    Attached Files:

    Last edited: Nov 27, 2016
  2. kemijo

    kemijo

    Joined:
    Apr 7, 2014
    Posts:
    18
    Oh btw, for anyone trying this, just tap up or down for vertical input, and don't tap again until the cubes have come to rest :)
     
  3. Fabian-Haquin

    Fabian-Haquin

    Joined:
    Dec 3, 2012
    Posts:
    231
    Hello kemijo

    I have some trouble opening your unitypackage, which Unity version are you using ?
    It look like the package wasn't exported correctly, can you try to export it again ?
     
  4. kemijo

    kemijo

    Joined:
    Apr 7, 2014
    Posts:
    18
    Hi Fabian-Haquin,

    Thanks for looking into this! I exported it using the Unity 5.5.0b3, sorry I should have mentioned that (perhaps I shouldn't be doing performance eval with a beta...) I was able to import it back into the beta no problem. I installed 5.4 and it imported but was pretty messed up, so I assume that's the problem. I will recreate the package with 5.4 and repost.
     
  5. kemijo

    kemijo

    Joined:
    Apr 7, 2014
    Posts:
    18
    I've attached the remade package in Unity 5.4. Feel free to download this version and 'import package -> custom package', then open the scene and test the up and down arrow keys. Thanks!
     

    Attached Files:

  6. Fabian-Haquin

    Fabian-Haquin

    Joined:
    Dec 3, 2012
    Posts:
    231
    Well, this is clearly a bad use of the Animator Controller.

    For simple animation like this, Animation Class is very more useful and easy to use.

    Animator controller is made to blend easily between a lot of animation like a character who run, jump, etc...
    In your example, the Vertical input should be used to blend between at least two looping animation with a BlendTree system.
    (https://docs.unity3d.com/Manual/class-BlendTree.html)

    I've updated your package with an Animator using BlendTree and another using a trigger.
    About your latency, the key is to adjust when and how long the blending is done in the transition's inspector.

    For the BlendTree example, just double click onto the BlendTree node to see what's inside.
     

    Attached Files:

    theANMATOR2b and kemijo like this.
  7. kemijo

    kemijo

    Joined:
    Apr 7, 2014
    Posts:
    18
    And there it is :) The trigger example is what I needed and its responding as fast as the Legacy Animation setup. Perfect!

    Yeah I know this isn't what Animator Controllers are intended for, and my actual use scenario is more complex than this (plus I figured my setup was also just bad). However my issue was the speed difference I was getting between Animation and Animator. I had tried trigger before and couldn't get it to do anything.

    In my actual game I am currently using Legacy Animation in much the same way my example was, but I wanted to use Animator instead because I read Legacy will be phased out, is that not true? I'd prefer not to use deprecated tools if they are going to disappear eventually.

    I'm unclear on the blend tree example. It isn't behaving the way the others are so its hard to tell if it will do what I need, whereas trigger is doing exactly what I need. I will read up on it though.

    Thank you so much for your time! Really helped!