Unity Performance Optimization Ⅲ: Animation Module

Some teams often ask: Why is my game loading so slow, can it be possible to cut scenes like other games? What is the reason why the game makes the device temperature rise? In order to prevent the game that you have worked so hard from getting stuck on the real device or the turn into a hand warmer, we must make full use of the loading module and resource management module in the our report, and we will analyze it step by step:

We have explained the performance optimization knowledge points of Unity’s mainstream modules one by one four years ago, commonly known as “Basic Version”. As the engine itself, hardware equipment, production standards, etc. have been upgraded in recent years, we have also continued to update optimization rules and methods and continue to output to the majority of developers. As an “upgraded version” of the performance optimization manual, [Unity Performance Optimization Series] will try to express it in a simple and understandable way, so that more developers can use it. In this issue, we will continue to share the knowledge points related to the animation module.

Currently, in UWA report, we can see that the main functions related to animation include:

There are two Animator-related functions: one is DirectorUpdateAnimationBegin and the other is DirectorUpdateAnimationEnd. Generally speaking, we must pay attention to the stack of these two functions, and further locate the cause through the number of calls of the stack function and the proportion of time consumed. Common factors affecting performance and optimization countermeasures are as follows:

1)Control the number of Active Animator

The number of characters increase will lead to an overall time-consuming increase, and the CPU time of each function increases approximately linearly with the increase of the character data.

The above picture is a real-device evaluation report of a project. We selected a frame to check its stack information and found that the number of calls to ApplyOnAnimatorMove is up to 168 times, which means the current scene there are 168 Animators in the Update state this value is very high. In general, it is recommended to keep it within 30 as much as possible.

The reason for this high value is usually the CPU time caused by a large number of off-screen Animators that are still updating calculations. It may be caused by the Animator component of the cached character being still in the Active state, or it may be caused by too many Animator components on the UI. For the Animator on the UI, if the animation is relatively simple, it is recommended to try to use Dotween instead.

2) It is recommended to check the number of Animators that “turn on ApplyRootMotion”

According to the stack analysis of Animators.Update, we can see that Animator.ApplyBuiltinRootMotion proportion up to 28%. This item is usually related to a model animation in a project where Apply Root Motion is turned on. If the animation does not require displacement, you do not need to turn on this option.

33
31 комментарий