Lesson 76 +10 XP

Optimization Best Practices

Optimization Best Practices

Optimizing a game involves reducing the workload on both the CPU (scripts, physics, draw calls) and the GPU (vertex count, pixel rendering, fill rate).

1. Reducing Draw Calls (Batching)

  • Static Batching: Combines stationary GameObjects that share the same Material into a single mesh. Check the Static box on objects.
  • Dynamic Batching: Automatically groups small moving meshes.
  • GPU Instancing: Draws multiple copies of the exact same mesh (e.g. grass, trees, bullets) using a single draw call, even if they have different positions. Enable "Enable GPU Instancing" on the material asset.

2. GPU & Rendering Optimizations

  • LOD (Level of Detail): Automatically swaps out high-resolution models for lower-polygon versions as the camera moves away. Add the LOD Group component to the parent object.
  • Occlusion Culling: Disables rendering for objects that are completely hidden behind walls or columns, saving GPU cycles. Bake occlusion under Window -> Rendering -> Occlusion Culling.
  • Reduce Overdraw: Avoid overlapping semi-transparent sprites or particles, as rendering pixels multiple times in a single frame slows performance.

3. Physics Optimizations

  • Adjust Fixed Timestep: If your game does not need precise physics, increase the timestep in Project Settings to reduce the frequency of FixedUpdate calls.
  • Simplify Colliders: Avoid Mesh Colliders on moving objects; use combinations of primitive colliders (Box, Sphere, Capsule) instead.

TL;DR

  • Batching merges meshes to reduce CPU draw call counts.
  • Use LOD Groups to swap out models based on distance.
  • Occlusion Culling hides objects that are blocked by solid walls.
  • Replace Mesh Colliders with primitives for faster physics calculations.