← Back to blog c sharp

65+ Tips: How to improve a Unity Game's Performance

by Michael Sacco Nov 28, 2023

Is your Unity project feeling sluggish? Are you trying to optimize your game’s performance?

We’ve compiled a comprehensive list of Unity performance optimization tips to help you improve your game.

From utilizing the Profiler effectively to mastering texture management, these strategies will ensure your game runs smoothly on any platform.

Profiler and Debugging

  1. Use the Profiler.
  2. Profile on your target device.
  3. Don’t optimize code unless you confirm it’s an issue with the profiler.
  4. If you see Gfx.WaitForCommands in the Profiler, you are CPU-bound.
  5. If you see Gfx.WaitForPresent in the Profiler, you are GPU-bound.

Physics Optimization

  1. Avoid empty OnCollision and OnTrigger callbacks.
  2. Use NonAlloc physics queries.
  3. Use the Physics Layer Mask matrix to simplify your Physics scene.
  4. Avoid Mesh Colliders.
  5. Avoid destroying or moving static objects.
  6. Use the Static flag to signal static objects.
  7. Combine simple meshes to reduce object counts.
  8. Split complex meshes to enable occlusion and frustum culling.

Resource Management

  1. Cache GameObject and Component references.
  2. Reuse materials whenever possible.
  3. Reuse textures whenever possible.
  4. Use texture atlases or virtual texturing.
  5. Reduce your texture resolution. Reduce it again.
  6. Never disable mipmaps.
  7. Use LODs.
  8. Use imposters.
  9. Use Scriptable Objects whenever possible. They help you avoid duplicating data.
  10. Use object pooling.
  11. Use high compression for textures.
  12. Use power of 2 resolution for textures.
  13. Pre-allocate and reuse arrays and lists when possible.
  14. Compress your audio.

Graphics and Rendering

  1. Use vertex lighting for secondary light sources.
  2. Use simpler shaders. Avoid complex calculations. Approximate everything.
  3. Avoid real-time lighting and shadows. Bake your lighting, bake your shadows.
  4. Set your near clip as far as possible.
  5. Set your far clip as near as possible.
  6. Set your camera Field of View as narrow as possible.
  7. Use Dynamic Resolution Scaling.
  8. Avoid transparent materials.
  9. Avoid alpha clip materials.
  10. Reduce your poly count. Reduce it again.

UI Optimization

  1. Split up your UI Canvases.
  2. Make sure all UI Elements on each Canvas share the same Z value, materials, and textures.
  3. Avoid Graphic Raycasters.
  4. Disable Raycast Target.
  5. Avoid grid views in your UI.
  6. Avoid large lists of UI elements.
  7. Avoid overdraw for UI elements.
  8. Avoid layout groups.
  9. Disable UI objects before re-parenting them. (e.g., when Object Pooling).
  10. Disable Camera rendering when a fullscreen UI is up.

Code Efficiency

  1. Use Coroutines to process loads over multiple frames.
  2. Use Burst compiler to run native code.
  3. Use Events to avoid continuous Update() checks and calculations.
  4. Avoid unnecessary string creation or manipulation.
  5. Cache and reuse WaitForSeconds objects - new WaitForSeconds() generates garbage.
  6. Avoid LINQ expressions.
  7. Avoid RegEx.
  8. Trigger Garbage Collection at opportune times using System.GC.Collect.
  9. Use Incremental GC if you’re struggling with significant GC issues.
  10. Avoid running code every frame.
  11. Avoid heavy logic in Start, Awake, and OnEnable. Consider Lazy Loading.
  12. Debug.Log statements are included in Builds. Disable them before shipping.
  13. Use Hash IDs instead of String values for Animator, Material, and Shader properties.
  14. Avoid adding components at runtime. Instantiating a prefab with the component on it is typically faster.

General Optimization

  1. Disable any unused GameObjects.
  2. FPS shows average frame time, but your players feel the worst individual frame, so you should aim for consistently high FPS.
  3. Use Layers for Raycasts and UI.
  4. Set a specific time budget for each frame. Common targets are 33.33ms (30fps), 16.66ms (60fps), and 8.33ms (120fps). Track your FPS from code, then issue warnings when you dip below your target.

Continue reading

Non-static method requires a targetHow to make a countdown timer in UnityPricing Strategy for Indie Game DevelopersUnity: How to Change Your SkyboxHow to add Friction to a Rigidbody in UnityUnity Standard Assets: The Essential GuideTop 10 Recent Games Developed with UnityUnity Sprite MasksHow to move or copy a Unity projectThe Ultimate Guide to Sun and Moon Positioning in Super Simple Skybox for Unity

Build your game with OccaSoftware

Learn on the go. Try OccaSoftware for free, and explore all the tools and assets you need to start, build, and launch your game.

Start now

Try OccaSoftware for free, no commitment required.