circle-loader
0
by
0/ 2171/ /5

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, UWA has 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.

https://lab.uwa4d.com/lab/5b442633d7f10a201faf59b4

 

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:

 

1Control 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 i, 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.

 

3) Turn on the Optimize Game Objects option

In the checked state, Unity will remove the hierarchy information of Transform when processing the animation clip. This setting is very obvious for the time-consuming improvement of Animators.Update, which can greatly reduce the time-consuming animation of the main thread, and free up valuable main thread time for more complex calculation logic.

 

4) Control the trigger frequency of Animator.Initialize

Animator.Initialize will be triggered when the GameObject containing the Animator component is Active or Instantiate, which takes a lot of time. Therefore, it is not recommended to perform Deactive/ActiveGameObject operations too frequently on the GameObject containing the Animator during the battle, as shown in the figure below.

We suggest that for frequently instantiated characters, try to deal with the buffer pool. When you need to hide the character, do not directly Deactive the GameObject of the character, but DisableAnimator component, and move the GameObject out of the screen, thereby reducing the frequency of Animator.Initialize calls.

 

5) Too many Animator Controllers in AlwaysAnimate mode

CulI the AlwaysAnimate state, when the character is off-screen, Update cost will continue to be generated. It is recommended to change this option to CullUpdateTransforms or CullCompletely. CullUpdateTransforms applies to Animator Controller whose animation will displacement, and CullCompletely is suitable for Animator Controller whose animation does not displacement.

 

6Animators.FireAnimationEventsAndBehaviours

It is the specific time-consuming of the animation event, mainly the performance cost of the project logic code. In this case, it is recommended that the R&D team further investigate the animation event.

 

7) GPU Skinning+GPU Instancing is recommended for group animation rendering

It is recommended to turn off the native GPU Skinning operation of the Unity engine. This operation will cause additional costs and cause invalid waits in the main thread or rendering thread.

At the same time, for many of the same kind of monster’s needs, we highly recommend rendering through GPU Skinning and GPU Instancing in the open-source library, which can reduce the time-consuming of Animators.Update and achieve the effect of batching.

Related open source library links:
https://lab.uwa4d.com/lab/5bc6f85504617c5805d4eb0a
https://lab.uwa4d.com/lab/5bc5511204617c5805d4e9cf

For your reference, the above are the common problems we encountered when optimizing the animation module. For efficiency, the editor still provides you with a very routine but really efficient method [We should always do printing presses instead of hand-made coins ]. You can refer to the performance briefing and press ctrl+f to search. “Animation”, if the animation module in your report is not healthy, you will see these unpassed detection items soon:

Similarly, in our static resource detection service, the following 4 detection rules are also provided for animation resources to help you further comprehensively investigate the rationality of the related settings of animation resources.

  • Compression != Optimal animation resources
  • Animation clips with too high precision
  • Animation clip containing Scale curve
  • AnimatorController with the too high number of AnimationState

The above are some of the issues and corresponding approaches that need to be paid attention to when optimizing the performance of the animation module. How to operate still needs to be combined with the actual situation of the project. UWA GOT Online has provided a wealth of detection functions, and hope to be a good assist for everyone to optimize the animation module.


Unity Performance Optimization Series

Unity Performance Optimization – Rendering Module

Unity Particle System Optimization: How to Optimize the Special Effects of Skills

Related Topics

Post a Reply

Your email address will not be published.