U3D Optimization Technology

Source: Internet
Author: User
Tags exception handling mathematical functions unsupported
First, batching technology: in owning a grid and carrying a different material time will form an independent drawcall, in the notification GPU and switch material shader texture time is also more time-consuming (especially the first CPU->GPU pass texture data). The main goal of batching is to combine the material of objects, so long as they use the same material (textures and shader), the GPU can be processed in exactly the same way (batch merge Drawcall). The algorithm of batching processing technology is: Check all the materials to draw objects, the same material of the game objects into a group, so that you can handle multiple objects in a drawcall. Unity in the scene first to visually crop the object, and then batch processing, so that the total amount of geometry in the rendering process before and after the batch to remain unchanged. The use of geometric modeling tools prevents the engine from effectively cropping, resulting in the need for more geometric patches within unity. Static batching chooses static for the game object and requires additional memory to consume the merged geometry data. Using game objects to create a shared grid consumes too much memory and reduces memory usage by removing the static. Dynamic game objects have the same material unity will automatically batch, no need for any settings. However, dynamic batch processing is limited and conditional. A grid object with a position, normal, and UV can only handle objects with a total of 300 vertices merged batches, exceeding unsupported. An instantiated game object with different textures cannot be batched, a Lightmap game object cannot be batched, and multiple pass shader materials will prevent batch processing, and objects that receive shadows will not be batch processed.
Second, Unityprofile Analyzer use: You can view CPU, memory, GPU, rendering, physical and audio consumption (can be added in the upper left corner, you can check the corresponding page to the left click X Remove), to find the performance of the game bottlenecks. 1 window->profile window click Record, click play button. 2 Unity will record the performance of the operation, click anywhere on the timeline will be at the bottom of the window will display the selected frame details. 3 The upper part will display the parser control, click on the timeline will suspend the display frame details, frame up and down is the previous frame next frame, current is the last frame. Click Deep Profile is the depth analysis will analyze all the script function calls easily die, Profile editor is the analysis editor, clear is clean.
Each view should be noted below, analysis of the meaning of each field, do not understand the Google under. For example: In CPU Analysis: Total is the time spent by the function and its child functions, self is the time consumed by this function. Click the hierarchy item item and the right side displays the details. The same is true in the GPU. This information can be used to optimize game object settings, enabled features, and optimize scripts. Memory Analysis: Gfxdriver is the memory required for graphics drivers to render in textures, render objects, shaders, and so on. In detail mode, the referenced from native code object is a reference to unity itself. Scene object objects from the scene game object. The Builtin resources object comes from the unity-built resource.
Parser interfaces are used in code: Profiler.beginsample (name:string) can be used for the limitations of unity deep profile analysis; Name is the sample label profiler.endsample (); The manual turn on and off feature analyzes the code snippet between Beginsample and Endsample. Example: Using Unityengine; Using System.Collections; /*samcen*/public class Profilerexample:monobehaviour {
private int sum = 0; void Start () {profiler.beginsample ("Myprofiler"); for (int i = 0; i < i++) {sum = i; print (sum);} Profiler.endsample (); To mount the script in the game object, you can see the results of the analysis (because it is in start) in the detail panel of the profile start frame.
Different devices are connected to the Analyzer: The iOS device is connected to the Analyzer: Select Build setting->development build->auto Connect profile, and then select active in Profiling view Profile to select the device, you can analyze. Make sure that the iOS device is connected to WiFi, make sure that the Mac firewall is down, or that the 54998~55511 port is open. In Unity, open File->build & run in turn. We can analyze the game's running in iOS in the Unity Analyzer.
Android devices are connected to the analyzer: like iOS, there is more to make sure that Android devices turn off the phone data, turn on WiFi, and set up a project like iOS to open Auto Connect profile, and after Unity opens the profile window, Select the active profile option to open the parser. Select Unity File->build & Run to open the application on the Android device. The Android device and the host calculator must use the same subnet.
Third, Unity frame debugger through frame analysis, to analyze each frame of the GPU, Draw call and render texture image information, as well as depth caching, template caching, Multi-target FBO information. You can also use external tools to debug the rendering. Play a separate play pack, run with the Visual Studio Graphics debugger, Intel GPA, Renderdoc, NVIDIA nsight, or AMD GPU Perfstudio, and then grab one of the rendered frames, and gradually debug draw calls and its It renders the event to see what is happening.
Iv. Optimization recommendations 1. General optimization Recommendations: 1. The fixedupdate is used in the physical engine and is performed at regular intervals. Update is called per frame and the interval is not fixed. Try not to write too many code in it that does not require repeated calls. There are empty fixedupdate, and update is also removed to avoid the function call overhead per frame. 2). Update, fixedupdate do not use the Find, Findobjectoftype, Findgameobjectswithtag, getcompoent<t> () and other time-consuming functions. 3). Update, fixedupdate do not apply strings, arrays, etc. to heap memory resources for frequent application and release. Also do not use too many temporary variables in the Hotspot function, such as too many stack variables are time-consuming, pay special attention to heap variables.
4. The above 1,2,3 operation can be placed into the awake, the start function. Code does not need to be executed per frame, it is resolved with coroutines, such as: void Start () {invokerepeating ("dosomething", 1.5f, 1.0f); 5). Manually recycle the garbage memory when the game switches the checkpoint, or pauses. Resource.unloadunuseassets (), GC. Call to Collect ().
2. In mobile devices: Physical performance Optimization: 1 optimization of the physical engine, in Edit->project setting->time, increase the number of fixed timestep, reduce the physical engine frame calculation interval, reduce CPU load. The value for setting the maximum allowed Timestep is 0.1, which is 10 times per second. 2 instead of using the grid collision body, wheel colliders The wheel collision body, but uses the Box,sphere shape collision body, reduces the computational overhead. 3 Avoid using the unity of sphere and other mesh components, because there are too many patches, need to be imported from other modeling software 3D model substitution. 4 You need to control the number of rigid and colliding bodies in the scene, you can use the Profile tool to determine the number of activities. Script optimization: 1 in the update function, reduce the getcompoent call, reduce the string, the array of heap memory resources to request and release. 2 Minimize the use of guilayout as additional memory overhead is required. By using the Usegulayout as false, a manual layout with the GUI can be substituted. 3 Do not use exception handling, such as iOS, Unity settings in the exception options in Project Setting->player: Fast and exceptions unsupported (not using exceptions), rather than using slow and Safe (mono internal use, support exception). 4 optimization of variables, as far as possible with the int rather than float, as far as possible with simple expressions, such as bitwise operations, as far as possible without complex mathematical functions.






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.