Sponsored By

Featured Blog | This community-written post highlights the best of what the game industry has to offer. Read more like it on the Game Developer Blogs.

Practical Tips: Maximizing Your Unity Game's Performance [Part-2]

Practical tips on increasing game performance in Unity - Part 2

Mahesh Athirala, Blogger

August 3, 2020

6 Min Read

This is the final and Continuation of Game Optimization tips PART-1

                           

Using real-time shadows in your game will take performance turning off will increase a lot of your game performance but shadows are most important for any game without its game looks unrealistic. Creating fake shadows using a blob shadow projector will take very little on performance as compared with real-time shadows. Thus, it’ll increase considerably high FPS on low-end configuration devices.

                  You can find and experiment about Blob Projector shadows in Unity’s Standard Assets

if your Game Objects are static use simple Fake shadows draw on the texture using material and if your Game Objects are dynamic(moving objects) use blob projectors whenever possible for your game.

                          

    Level of Detail or LOD are most often a method to allow us to display meshes in different polygon counts depending on the camera distance. Simply, if the camera is near to the object you may see object model at High quality and when far you may see a low quality this technique considerably increases rendering performance.

By Default Unity will use the same number of triangles to render the object at both distances, this can result in wasted GPU operation which can impact performance for your game.

You can configure LOD levels in your 3D modeling application and unity can automatically create and configure the required GameObjects and components for you or you can manually create a Game Object with a LOD group component and configure the LOD levels manually.

                          

When it comes to optimizing, scripts play a huge role and quite limited. Writing unnecessary code in your game might considerably reduce your game performance. These are the common sectors that we can improve.

          

      One of the biggest mistakes is keeping everything inside Update function even if it's not necessary calling every second. For Instance, updating a UI score writing it on the update will keep on calling every second instead of updating it when there’s a change. Try to use very few Update functions as much as possible instead of writing multiple updates when you have multiple Game Objects.

        Coroutines will be the best in the place of Update method just by updating a value at a particular time you specify. With coroutine you can control the frequency of calls, if you are doing something expensive which doesn't have to be done every frame then it's better to have it in a coroutine.

        

      There are several approaches for resolving a reference to a Game Object in your scene.A common mistake is to use object’s name with GameObject.Find method which will look through all the Gameobjects and other Game Objects children which will be a bad practice.

      This will be usually used to find a GameObject and to get access of it. To get access it might be better to use the public or use GameObject.FindWithTag. It’s always best to find these in Start or Awake methods or manually assign these objects by declaring as public whenever you have the possibility.

 

  Pooling is often used for objects to reuse them over and over again without destroying them.this is useful for objects that are used very often. For Instance, the player shooting bullets instead of Instantiating and deleting we can use Pooling just by disabling and enabling after sometime when needed.

 

  If you’re not using something, turn it off unless there’s a reason to constantly update in your game. Turn on what is necessary and disable the rest also comment Debug.Log() in the final build when you have the possibility.

                          

 Physics calculations are performance taking based on your scene in Unity, these are the few that are used quite often.

 

  You have a number of different colliders like box colliders, to capsule colliders, mesh colliders, sphere colliders, and even 2D based colliders. Its good to use primitive colliders whenever possible such as box, sphere, or capsule. Mesh Colliders will be generated based on your model mesh. Nonconvex based Mesh colliders will generate most contact points when compared to normal primitive colliders.

Using high poly mesh colliders is incredibly expensive will considerably decrease your game performance and should be avoided if possible. Converting from high poly to low poly then using mesh collider will be better.

 

  Rigidbodies are used to add weight to any of your Gameobject, so that it can be affected by physics such as gravity and other object forces. it's always good to have limited rigid bodies in your scene having too many within your game will affect your game performance.

Controlling the rigid bodies when they should sleep can also improve your game performance. Especially on mobile devices try to have the least dynamic rigid bodies because they demand a lot of performance. If possible try to keep the Rigidbody collision detection mode to discrete, as dynamic will take a lot of performance.

 

      Physics Debugger is a great tool for quickly inspect colliders and to profile physics-based in your scene. It provides an overview of which rigid bodies are sleeping, which game objects are static, which are collided with each other.if you have many colliders in your scene this is very useful.

It provides a visual representation of complete physics-based moments happening in your scene.

                         

 UI is the most common optimization and can be expensive if it's not efficiently organized for your game. Here are a few ideas to get the best performances!

 

     The Canvas is the basic component of Unity UI. Which will be a parent for all your UI elements placed on it by generating meshes.When any UI element on a canvas changes, the whole canvas regenerates, and issues draw calls to the GPU so that the UI is displayed.

 

Setting up all the UI under a single Canvas is very bad idea beginners who haven't had much experience with unity often do this. When we change something in one element there will be a CPU spike costing multiple milliseconds. Using multiple canvases is a solution to reduce CPU usage.

 

      The Graphic Raycaster is used to determine if the cursor is over Graphics elements. It translates screen/touch input into Events, and then sends them to interested UI elements. Graphic Raycaster performs often checks on UI elements that are to be interacted.

When any Canvas that doesn't need any interaction Disable Raycast property for all the non-interactive elements this will stop Graphic Raycaster to check the number of interactions each frame.

       I'm a Game Designer and Co-Founder at Street Lamp Games. I'm obsessed over making Prototypes, breakdown core design values, new design techniques, and dedicate an insanely amount of time to create an amazing player experience. And also sometimes I create speed level designs in my spare time.

You can find me on Twitter and LinkedIn

 

 

Read more about:

Featured Blogs
Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like