Common performance issues with unity game projects

Source: Internet
Author: User

The Unity technical support team often reviews and optimizes the performance of the game project for the required customer company projects, and there are many more common aspects of the various project-related issues we have encountered, and here we have listed some common questions and categorized them, and the developer friends can refer to them.

Resource Import

<ignore_js_op>



    • Texture is not compressed


In many cases, art will feel that the texture after compression effect is not ideal. We recommend that the resolution of the original image can be extended by a maximum of one time, maintaining the original compression format. In this way, the compressed file is smaller than the uncompressed file, and the visual effect can be greatly improved.

    • Read/write enabled in texture import settings is checked


Turn on texture import settings Read/write Enabled, the data on the CPU side remains in memory after the texture is uploaded to the GPU. Memory consumption is doubled due to shared memory on the mobile memory. It is therefore important to note whether there are textures that need to be accessed on the CPU side, such as the need to get texture pixels through a script, to turn on read/write Enabled in the texture import settings.

    • Model file Import settings Read/write enabled is checked


In addition to the meshes that need to be accessed in the script, as meshes in the Grid collider, in scripts with staticbatchingutility.combine static-batch meshes, and in addition to the grid emitted by the particle system, other models do not recommend checking this option. Otherwise, a copy of the grid instance occupies memory in memory.

    • Model import settings [Rig] Options page optimize Gameobject not checked


It is recommended to turn on the optimize gameobject, which can remove the nodes used for skinning in Scenemanager, save the scene node tree update and the CPU consumption of the query, and add the node to the exception list for the nodes that need to be hung.

    • Unity built-in audio is not disabled when using third-party audio plugins


When you do not need to use the unity built-in audio module, it is recommended that you disable the Fmod module completely by checking Edit->project settings->audio->disable Unity audio in the editor. Avoid unnecessary CPU consumption

Common CPU Performance issues

<ignore_js_op>



    • Frequently-called Camera.main


It is recommended that the script do the main camera cache. Camera.main is actually called Gameobject.findgameobjectswithtag ("Maincamera"), mainly because the engine is not aware of the high cost of MAINCAMERA,CPU that the user has set through the script.

    • A large number of unityengine.object operations in the script


It is recommended to use Instanceid to judge the object. Getinstanceid, guaranteed unique during operation. Because of the extra time-consuming operation of object sentencing, the int type is very fast. Similarly, the data structure using object as key is also recommended to use Instanceid as the key.

    • Data used for querying operations using the list data structure


The contains of the list linear structure is very time consuming and it is recommended to change the data structure of query operation with Hashset,hashtable.

    • No limit on the number of asset loaded per frame from Assetbundle when loading resources


The number of asset loaded per frame from Assetbundle in the scene is recommended to be limited to 2 to 5, which can be long enough to cause the high number of cards.

Memory FAQ

<ignore_js_op>



    • There was a spike in memory when loading the scene.


The common case is that there are no indexed resources to be loaded in, and then because the unloadunusedassets is unloaded. Memory spikes are basically useless memory for the game itself, but may cause the game to be forced off on memory-strapped machines.

    • Memory leaks due to static indexes


Some memory-intensive resources such as textures, because there are static indexes and cannot be unloaded when switching scenes or calling Unloadunusedassets, so the amount of memory leaks increases as the number of times the user switches the scene.

    • The total size of the mono memory pool is larger than the current usage size


The larger the value, the more unnecessary memory pool extensions, such as having loads of resources in the same frame, instantiating a large number of objects, and potentially inflating the memory pool in an instant.

    • Large GC Allocation amount


In addition to CPU time consumption and memory allocation, we also pay attention to the GC allocation of the script function during the review of the project. The more frequently the GC is allocated, the greater the amount, because the more frequent the gc.collect (one of the reasons for Kaka) is called due to the lack of available memory in the mono memory pool, and may cause unnecessary expansion of the mono memory pool, so the GC allocation amount of the script function is an important parameter that affects both the CPU and the memory. For the GC allocation amount.

The reference values we recommend are:
For a function that allocates a GC on a basic basis per frame, the recommendation for a GC allocation greater than 2KB confirms that it is possible to extract the temporary variable.
For functions that occasionally allocate GC, the recommendation for a GC allocation greater than 10KB confirms that the allocated data structure has an optimized space.

Common GPU Performance issues

<ignore_js_op>



    • More passes are rendered with special effects


Some special effects can be combined into the same pass to save GPU overhead, and rendertexture can be shared as much as possible.

    • Too many of the same screen faces


The same screen surface number is recommended under 20W, the better case is controlled within 10W

    • UI elements use the setting Alpha to 0 when they need to be hidden


In fact, the GPU still needs to render the UI mesh, and it is not recommended to hide the UI by setting Alpha to 0.

    • When using grids as terrain, properly slice the terrain grid


It is necessary to rely on hardware clipping to reject vertices when the number of vertices in the mesh is high, and to compare GPU performance, it is recommended to slice the terrain grid according to the approximate visible range of the same screen.

    • The UI element relies too much on the blending of multi-layered elements to achieve artistic effects


This will result in more overdraw, and it is recommended to try to achieve the desired effect by pre-fabricated textures.

Common performance issues with unity game projects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.