Unity3D Experience (2) - Primary Performance Optimization

Overview of issues

When a game truly entered the testing phase, it will be a performance optimization not avoid the issue. Sometimes you may find obviously a very simple game, it was an extremely serious dropped frames, wake up, not to suspect that your computer is configured, in most cases still own the optimization of the program is not in place.
As a beginner, read the blog + after several days of use unity comes profiler Performance Analyzer, summed up the following points.

Optimization Tips

1, the UI instead Sprite
Unity UI rendering will account for a larger memory, although the need to use Sprite extra perspective to follow a script, but it can save rendering time.

2, down to a low vertical synchronization arranged
vertical synchronizing meaning that the application period is synchronized image frames adjacent to prevent tearing. But you can see through profiler, vertical sync will take a lot of time, turn off vertical sync, although occasionally may cause the screen to crack, but can greatly increase the frame rate operation.

3, to reduce unwanted Component, especially Animator and rigidbody
unwanted components is extremely hurtful thing, because unity is the engine in the calculation will not ignore any one component.

4, for the need to use Trigger objects can reduce the number of objects collide class of
thing that makes me a very unexpected. Can be seen through profiler, be restricted if the category body does not collide, sometimes ontrigger () will look to detect thousands of objects, which also increases the read function OntriggerStay lot of pressure.

5, into the Start GetComponent and Find function, must not be present in the update
method is a kind because GetComponent Find and type of traversal, more map objects, loss of their longer time, if at this time and then update each frame of the caller, then dropped frames, of course inevitable.

6, internal calculations for complex functions, called once every few frames
is equivalent to reducing the burden to the engine, giving it the opportunity to recuperate.

7, will not affect Active placed out of sight of the object to false
This operation is a show for a larger map, if you really can do this one, then it will reduce the pressure of the engine particularly large, but it not a common approach, because many games can not see where there will be many events occur.

8, reducing the frequently called functions, in particular to avoid the update call the function
call the function requires additional space applications, and update constantly calling function will increase the pressure outside the engine.

9, be sure not to do with global variables Playerprefs, should inherit a global
plan focused! Playerprefs is simple and crude, but its memory speed and read speed is very very very very slow, a bit like opening a file and then retrieve the speed, if you dare to use Playerprefs in the update, then it dares to put what you call burst frame . Recommended a new category Global inherit MonoBehavior, then all the rest of the class to inherit Global in unity in.

10, or to control the number of particles and the particle range of the system
the particles take up more larger and more complex the greater the calculated pressure, this obviously. Of course, promptly remove unwanted particles also need to pay attention.

11, try to replace with objectpool instantiate object and destroy object
object pooling is a good thing, it can be all the temporary prefabricated objects in the pool, and so on when they need to be generated directly out enough to avoid time and time again due to new prefabricated performance degradation.

12, the scene will import the new project, to discard all the imported without the use of Resource
This project is entirely in order to save space and reduce wasted space.

13, reducing the foreach to traverse great lengths to avoid even the appearance like the loop body
is not explained. update have been very frequent, then something quick to traverse, unity certainly will burst card.

14, when the comparison tag to make use of CompareTag ( "Tag") rather than == "Tag"
Here are some of the special usage. About tag itself is not very good performance, because the official CompareTag specifically to a method to compare the Tag, you can save a few milliseconds per frame, but the number can save time in the update is quite substantial.

Released eight original articles · won praise 1 · views 329

Guess you like

Origin blog.csdn.net/weixin_42921101/article/details/102374636