Lesson 74 +10 XP

The Unity Profiler

The Unity Profiler

The Unity Profiler is a diagnostic tool that helps you analyze your game's performance, identify resource bottlenecks, and optimize CPU, GPU, and memory usage.

Opening the Profiler

Open the Profiler window via Window -> Analysis -> Profiler:

  • You can profile your game running directly in the Unity Editor.
  • For accurate results, connect the Profiler to a Development Build running on a physical target device (e.g. an Android phone or game console) to measure real hardware performance.

Key Profiler Modules

  • CPU Usage: Shows which scripts or engine processes take the most time per frame. You can drill down into the Timeline or Hierarchy view to find specific methods (like expensive Update loops).
  • GPU Usage: Displays how long the graphics card takes to render shadows, geometry, and post-processing.
  • Memory: Tracks total RAM usage, separating assets (textures, meshes) from C# heap allocations and garbage collection overhead.
  • Physics: Shows the CPU time spent on colliders, rigidbodies, and collision checks.

Profile Markers in C#

You can insert custom checkpoints in your C# scripts to track expensive operations in the Profiler:

using UnityEngine;
using UnityEngine.Profiling;

void ProcessData()
{
    // Begin profiling block
    Profiler.BeginSample("MyExpensiveOperation");

    // Perform operations
    DoHeavyCalculations();

    // End profiling block
    Profiler.EndSample();
}

TL;DR

  • Open the Profiler via Window -> Analysis -> Profiler.
  • Profile on actual target hardware devices for accurate diagnostic data.
  • Analyze CPU, GPU, and Memory modules to locate bottlenecks.
  • Use Profiler.BeginSample and EndSample to track custom script logic.