- Home /
Animator.Update has high CPU usage
Hello! In the game I'm working on, we've got a lot of objects in each level that need to be 'ready' to interact with other objects in the scene. For instance, there are about 20 or so tree objects scattered throughout the first level.
I've been trying to improve the game's frame rate, and have hit a roadblock with the Animator's performance. Up until this point, most idle objects in our level that need to have animations (rocks, trees, etc) have been made with an "idle" state which has the object in its default state. Our "idle" animations have Loop Time disabled, and every animator has a culling mode of "Based on renderers".
However, even with these precautions, Animator.Update shows >50% CPU time in the Unity profiler, on the very objects (trees, rocks) that should not be updating (loop time is turned off). Under Animator.Update are "Animator.SendTransformChanged" and "Animator.AppleGenericAnimatedProperties", each using about 15-20% CPU time. The child processes under each don't seem to have any noticeable impact.
Is there a better way to handle idle/static animation states? It's going to be a pain if we have to end up disabling animators on everything and selectively enabling them at runtime. Is there something I'm missing? If these objects aren't currently animating, then why are "ApplyGenericAnimatedProperties" and "SendTransformChanged" using so much CPU?
Thanks in advance!
Answer by Kumo-Kairo · Apr 18, 2014 at 06:15 PM
In our project we actually downgraded all the animations to legacy system. It becomes even more useful when it comes to threes and static / idling objects. Framerate immediately skyrocketed from 30 to 60, so it's a truly great solution.
Animators indeed have lots of CPU impact. In fact, they take a lot of CPU time even if there are no animations attached.
To downgrade to legacy animation, you have to select your import model (where your animation is stored) and select Rig -> Legacy instead of Generic. Then remove the animator components and replace them with animation components. Simply drag your animation to the empty slot and select "Play automatically", you should also define your animation's WrapMode as Loop (in the import model window)
It is also said somewhere in the mechanim documentation that it's OK to use legacy animation sometimes to win some CPU time. (I can't find the reference, but it's there somewhere)
Thanks for the answer :)
Since our game is already far into development, that's not really an option for us. So many of our scripts rely on being able to set values on the Animator that it would take an enormous amount of time to refactor...
However, I did find a solution. Now I've made a script that can be applied to any object with a box collider that checks if the object is within the camera's frustum and, if it isn't disabled the animator until it is. Seems to work ok :)
You can make an editor script that will replace all your animators with animations in no time. It's not hard at all
But how could we translate scripts that currently have calls like "anim.SetTrigger("name")" etc?
Answer by Zullar · Nov 13, 2015 at 01:46 PM
I also am having the same problem. Even with objects off-screen and play no animation it really chews through the CPU. If I disable the Animator my framerate goes from 13-->30, and if I disable NetworkAnimator my framerate goes from 30-->35. I do not understand why it uses up so much CPU when I'm not playing any animation...