Improving Performance

Introduction

Unity is a very powerful platform and you can reach much higher simulation and visualization performance than in most traditional engineering tools. But you can still reach performance limits with models and scenes with 10 millions and more triangles. Unity provides a lot of things to improve. We describe here just our experience and our performance recommendations but there are for sure a lot of additional things you can do for improving performance.

Quick overview

Please always follow these rules - in order of the importance

Use lowest possible mesh quality when importing the CAD data. You should always take care about that first - changing later on could be quite some work

Do you want to create reusable components - export them as an FBX after export - or is it just a one time CAD model import and you don't need to create a prefab?

Set Gameobject static settings for everything which is not moving

Use not more than 3 lights in a scene

If you are an expert, change the render pipeline to URP (see below)

Replace the imported instantiated Material after the CAD import by shared Materials (Materials which are shared by all the meshes and which you can find in the Assets folder) - you can use MaterialWindow (only available in Professional version) or SelectionWindow for quickly assigning new materials.

Combine meshes which are in one kinematic hierarchy or which are not moving to one mesh by using the Performance Optimizer (only available in Professional version)

Gameobject Static settings

This is a very important setting with high performance impact - you should consider this always.

This is the most important performance recommendation. You should set all objects which are not moving (e.g. connected to a Drive) to Static.

Changing Physics Settings

You could also change the physics settings, e.g. the fixed update cycle time, to improve performance. More information can be found in section Physics

Simplifying meshes

The number of triangles in total in your project has also a huge performance impact. You should only import CAD data which are needed and you should simplify the meshes as much as possible. In smaller projects you don’t need to care about that, because Unity is per formant enough to visualize a lot of meshes. But if your project reaches more than 1 million meshes and if you encounter graphic cycle times bigger than 50ms you should thing about improving the performance of you meshes.

For improving the performance please follow these steps.

Importing

You should use a mesh quality while importing (e.g. with CADLink) which is good enought for a good visual appearance but not to high.

Checking your meshes with CADChecker (Professional version only)

With CADChecker you can analyze your meshes, find the biggest ones where performance improvements makes sense and detect unnecessary duplicates.

You should first optimize the meshes of your MUs and the bigger meshes of non static moving objects.

Simplifying already imported meshes

If you already imported your CAD data and you want to simplify single meshesy you can use 3rd party tools like for example Mesh Simplify (see https://assetstore.unity.com/packages/tools/modeling/mesh-simplify-43658)

Lights and shadows

ights and shadows play a critical role in creating immersive visual experiences in Unity, but they also have a significant impact on performance, especially when calculated dynamically by non-static objects during simulation.

When considering performance optimization:

  • Reducing the Number of Lights: Each light source in Unity adds computational overhead, as each light calculates its influence on objects within its range. By minimizing the number of active lights in your scene, you can alleviate this burden on the CPU and GPU, thereby improving overall performance. Evaluate whether all lights are necessary and consider combining multiple lights or using baked lighting where feasible.

  • Disabling Shadows: Shadows cast by lights enhance realism but can also be computationally expensive, especially when calculated in real-time for moving objects. Disabling shadows for lights can significantly reduce GPU workload. If visual fidelity allows, consider turning off shadows or adjusting shadow settings to balance visual quality with performance.

  • Static and Baked Lighting: Utilizing static lighting and baked shadows can provide substantial performance benefits. Static objects and environments can be precomputed for lighting and shadows, reducing runtime calculations during simulation. This approach is particularly effective for scenes with mostly static elements where real-time lighting calculations are unnecessary.

  • Optimizing Light Settings: Unity offers various light settings and parameters that can be adjusted to balance visual quality and performance. Experiment with light intensity, range, and attenuation settings to achieve the desired visual effect while minimizing performance impact.

Colliders

In Unity, colliders play a crucial role in determining how objects interact with each other within the game world. When considering colliders, the choice between using Box Colliders and Mesh Colliders can significantly impact performance.

Box Colliders are simple geometric shapes that approximate the bounds of an object using axis-aligned bounding boxes. They are efficient because they require minimal computational resources to calculate collisions. Box Colliders are ideal for objects with simple shapes like cubes or rectangular prisms, where the shape closely matches the collider.

Mesh Colliders, on the other hand, use the actual mesh geometry of an object to define collision boundaries. This provides precise collision detection for complex shapes that cannot be accurately represented by primitive colliders like boxes or spheres. However, Mesh Colliders are computationally more expensive because they require detailed mesh data for collision calculations. This can impact performance, especially when used on numerous objects or complex meshes.

Impact on Unity Performance:

  • Box Colliders are lightweight and efficient, making them suitable for objects with simple shapes. They contribute minimally to performance overhead, making them a preferred choice in scenarios where precise collision detection is not crucial.

  • Mesh Colliders, while offering accurate collision detection for complex shapes, can introduce performance overhead due to the computational resources required to process collisions based on detailed mesh data. Using Mesh Colliders extensively or on high-polygon models can lead to increased CPU usage and reduced frame rates, impacting overall game performance.

Best Practices:

  • Use Box Colliders for objects with simple shapes whenever possible to optimize performance.

  • Consider Mesh Colliders only when precise collision detection is necessary for complex geometry that cannot be approximated by primitive colliders.

  • Optimize Mesh Colliders by simplifying mesh geometry where feasible to reduce computational load without sacrificing collision accuracy.

Changing the rendering pipeline to Universal Render Pipeline

Universal Render pipeline is a little bit more complex than standard Render Pipeline. You should use it, when you need very good performance and very good visual quality.

Please note that this section is outdated. It explains the manual process of switching render pipelines which you can still do but since version 2022.11 you can automatically switch - for more information see section Render Pipelines

Our experience is, that by changing your project to Universal Rendering Pipeline you can improve your performance about 30%. But you should do this only if you are already a Unity expert and if you really need the additional performance.

You should follow these steps to change to Universal Rendering Pipeline. For more information please check the Unity online documentation.

Install URP

  • Open the Package Manager window (Window > Package Manager).

  • In the Package Manager window, in the Packages field, select Unity Registry.

  • Select Universal RP from the list of packages.

  • In the bottom right corner of the Package Manager window, select Install. Unity installs URP into your Project.

Creating the Universal Render Pipeline Asset

The Universal Render Pipeline Asset controls the global rendering and quality settings of your Project, and creates the rendering pipeline instance. The rendering pipeline instance contains intermediate resources and the render pipeline implementation.

To create a Universal Render Pipeline Asset:

  • In the Editor, go to the Project window.

  • Right-click in the Project window, and select Create > Rendering > Universal Render Pipeline > Pipeline Asset. Alternatively, navigate to the menu bar at the top, and select Assets > Create > Rendering > Universal Render Pipeline > Pipeline Asset. You can either leave the default name for the new Universal Render Pipeline Asset, or type a new one.

Adding the Asset to your Graphics settings

To use URP, you need to add the newly created Universal Render Pipeline Asset to your Graphics settings in Unity. If you don’t, Unity still tries to use the Built-in render pipeline. To add the Universal Render Pipeline Asset to your Graphics settings: Navigate to Edit > Project Settings… > Graphics. In the Scriptable Render Pipeline Settings field, add the Universal Render Pipeline Asset you created earlier. When you add the Universal Render Pipeline Asset, the available Graphics settings immediately change. Your Project is now using URP.

Upgrade your Shaders

Your Project uses shaders from the built-in render pipeline, and you want to switch your Project to use the Universal Render Pipeline instead, you must convert those Shaders to the URP Shaders.

Open your Project in Unity, and go to Edit > Render Pipeline > Universal Render Pipeline. According to your needs, select either Upgrade Project Materials to URP Materials or Upgrade Selected Materials to URP Materials.

If the Preview thumbnails in Project View are incorrect after you’ve upgraded, try right-clicking anywhere in the Project View window and selecting Reimport All.

Change the Shaders in your scenes

You might still see pink objects in your scene. This is because the materials in your scene might still have a standard shader set. You need to change all your materials in your scene to a new URP shader like for example Universal Render Pipeline/Lit.

You can do this manually but for bigger models you can use the Selection Window to automatically change the Shaders of all selected Gameobjects.

Profiler

For experts, Unity has an included Profiler. It is possible to measure all frames and to identify what functions are needing the most part of the time. Unity Profiler is started by Window > Analysis > Profiler

See more in Unitys documentation about the Profiler:

Performance Optimizer (only included in Professional Version)

The Performance Optimizer is a component that you can add to your imported CAD geometries. It combines meshes into a mesh with multiple materials to improve the runtime performance of your scene. The original meshes will be set inactive during the process. This combined mesh can be saved as a separate object. This object can then also be defined as static to achieve further improvements. You can also define kinematic groups to be included in the combined mesh. For further optimisation, you can also delete meshes that are represented by the combined mesh. Be aware that the undo-function don’t cover the rebuild if deleted meshes.

Properties

Create sub object for mesh: this option will create an empty game object to store the merged meshes. Create static mesh: the new created mesh will static. A static will only be caculated ones during runtime. Include non static elements: the merged mesh will also include non static meshes. Non-static meshes belong to objects that can be moved or move themselves during runtime. Exclude groups: Objects with the component group are not considered in the merge. Delete combined meshes: the original meshes used for the combined mesh are deleted after merging. Attention: This function CANNOT be undone. Included groups for mesh optimizer: Within this list you can define groups whose meshes may be merged. The Button “Optimize Meshes” starts the optimisation. The button “Undo mesh optimize” dissolves the newly created mesh.

Last updated