Unity3d Comprehensive Performance Tips

Source: Internet
Author: User

This article is the official document of unity in Luzexi translation: General_performance_tips

Official Tips Document

Excellent graphics performance (http://docs.unity3d.com/Documentation/Manual/OptimizingGraphicsPerformance.html)
How to reduce packet size (http://docs.unity3d.com/Documentation/Manual/ReducingFilesize.html)
Character animation (skill is scattered) (http://unity3d.com/Documentation/Manual/Character-Animation.html)

Overview of optimization techniques

Analysis The first step, do not try to spend time to optimize some obscure program or reduce the size of the picture unless you do know that they are bottlenecks. The first thing to do is to always analyze your game to find out where the bottlenecks are. Apple's shark is a great tool for analyzing the OpenGL Foundation app.
Analyze the second step and don't forget to re-analyze the game once you've optimized it to see if they're working, and you might find another bottleneck.

Development work first – performance optimization second. Spend as much time as possible to make your game smoother and smoother. The ability to make changes and updates to the game faster will also mitigate future performance changes. Test the scene in the observation screen, which tells you whether the performance is slowed down by the objects in the scene or by the script that is bound to the object. If you are slow in the watch screen, you may need to optimize the model or map, if not, the bottleneck may be in the program or physical collisions. Close individual game objects and try to turn off individual objects in the editor, which usually allows you to troubleshoot objects that are slow to play.

Model Grid

As much as possible, merge the neighboring models into a single model with a single material ball. For example, if you have many objects stacked on a table in your scene, merging them will make sense (it might be necessary to merge some stickers into a large map atlas). Reducing the number of objects that unity renders can significantly improve performance. A material ball a model, each material ball will be considered as a separate model for rendering. Using a model with extreme low modulus (below 500 polygons) can increase performance. Most graphics cards have conversion and lighting capabilities, which means they deal with strange polygons every second. And usually commits a grid to render the graphics card, so too much reduction in the model's polygons may make your game model look like blocky. Let's start with a 1500-2000-triangle character, which can change a lot, but as a starter the artist should have a better compromise on quality and performance at a level of detail. Note that if you have a model that uses quads, (quadrilateral) Unity will convert each quadrilateral into 2 triangles and then import.

Light

Each pixel light rendering will take effect for the additional render pipeline. Pixel light will make your game look better but don't be too enthusiastic about them. However, it is a good way to use Quality Manager to adjust the rendering of each quality level like light, which provides a balance of performance and quality in your published game.
Spotlights are more cost-performance than point and direction light. The best way to light a scene is to determine the effect you want, and then see which of the lights is important and which one can be cut to make the scene look similar to what you want.
The point light and spotlight values affect the model grid within their range. If the model is outside the point light and Spotlight range, the effect of the light will be weakened, and the model will not be affected by the light to save the performance cost. This approach can theoretically explain that having a lot of small point light sources but still has good performance, because they affect only a small part of the object. Remember that a model can be affected by up to 8 light sources.

Map

Minimize the size of the map if it seems acceptable. If your video card does not have enough memory to hold the stickers, they will be placed in the system memory and uploaded when they need to be rendered. There's nothing wrong with the new computer because they have a lot of room to use. But if you're obsessed with running your game on a low-end memory device, instead of changing the size of the map on the image tool, you can use Unity to import the picture and set it to size.
Do not use low quality image files, try to use JPEG low-quality files or low-color PNG or GIF files will not reduce the size of the game. Unity will automatically compress all the pictures when you package the release, so keep the original high-quality map file. In this way, compression and decompression of various ways to achieve quality change becomes very convenient.

Audio

With. ogg for audio compression, other audio formats are stored in the package as uncompressed PCM audio formats when the release is packaged.
With non-compressed audio for small sound effects, Unity (starting with 1.6) will unzip all OGG files when imported. It lets you use non-compressed WAV or AIFF files when playing short sound, so you can decompress the audio file without consuming the CPU. such as the rapid shooting, footsteps and other similar sounds.

Physical

Each rigidbody is consumed by calculations, so the fewer the more desirable. Existing Rigidbody objects are also best closed when their rotational speed and movement speed are reduced to a certain extent. When this occurs, a large number of computations are significantly removed and maintained at a lower amount until they are manually subjected to force or collide with other colliding bodies if they exist.
Complex collisions consume more computational complexity than normal, and a large number of spherical rigidbody colliding bodies stacked together will consume more complex computational processes than are far apart in the terrain.

Coloring device

Many complex shaders are more likely to consume performance than simple. The vertexlit diffuse shader should be the fastest shader with stickers and lighting. However, if no pixel lights are in the scene or all like light are turned off by quality manager, most shaders will fall back to a simpler vertex rendering version.

Script

1. Do you use a good algorithm? If possible, choosing a good algorithm will have a better effect on working income than other adjustments.
Note that the best algorithm is not always the lowest average complexity algorithm. For small data volumes, it is often better to use a simple low-speed algorithm than an intelligent algorithm with high initialization. (For example, you can use a hash table or a binary tree as a large data to be accessed by name, but you can have a simple list and linear algorithm if you access small data.) Although the dotnet hash table class in this case has chosen the best way to measure the size of your data. )

The 2.FixedUpdate method keeps as little logic as possible. These logic can be called about 50-100 times per second in each object of a valid script, so they are an important goal of optimization. If some logic does need to be executed after rendering the update, then put the code into the Update method.
If possible, turn off the scripts on some objects when they are no longer needed. If your game has a large scene where the monsters are a few kilometres away, you can turn off his AI scripts until the camera is close to them. Here's a good way to switch them, which is to use gameobject.setactiverecursively (false) and set the spherical and square collider as the trigger (trigger).

3. Be careful with the empty Update method. When new scripts are created using the Resource menu, they contain an empty update method. Get rid of it if you don't need it, because it brings some (small) performance cost. This performance consumption point applies all the overloaded methods in the Monobehaviour script, with the update and fixedupdate as the primary target.

4. With regard to the most logical component of a gameobject, one can theoretically write: Somegameobject. Transform. Gameobject. Rigidbody. Transform. Gameobject. Rigidbody.transform, but most of this is not needed. If you need to deal with an object's transform, you can map it to the beginning of your script.

5. Co-process is your good friend. The process has very little overhead and is more appropriate to be chosen, and an update method is always called when it is not needed. For example, you have a script that implements a gradual fade-out of a command trigger, and you can use the process to implement a gradual-fade-out replacement update. This is done most of the time when the light does not progressively fade out, and the script is the lowest performance drain. If the ramp-up is implemented in the Update method, you will be inefficient polling to see if the ramp-out is over.

6. Do not use methods to search for objects without the need, including methods Gameobject.findbytag () and Gameobject.getcomponent (), as with all convenient properties (transform,light, etc.), These methods can be optimized to run as fast as possible, but they still have to go through the search for the associated object to find the one you want. The most important thing is to avoid calling the search method in the update and Fixedupdate methods, Yu Zhi replaces the call to a method once and stores it in your class member variable, and then takes it from this member variable the next time you need it.

7. Do not use SendMessage (or a similar method) when you are not necessary, SendMessage is at least 100 times times slower than the direct call method, and this multiplier also increases when many scripts and methods are in effect on an object. If you can get your script you'd better get to it as soon as possible and call this method directly.

The duck type of 8.JavaScripts (and boos) consumes a small amount of computation. In the performance 0 bounded area and when using JavaScript, try to declare directly the type of variable you are using. (although this is usually the computer will automatically recognize the valid type you specified, so your program can be diversified)

Transferred from: www.luzexi.com
E Text: http://wiki.unity3d.com/index.php?title=General_Performance_Tips

Unity3d Comprehensive Performance Tips

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.