In this lesson, you will learn how to navigate the Profiler’s Hierarchy view to surgically identify which specific scripts and methods are consuming the most CPU time during your game loop.
Analyzing the Hierarchy View
Once you have established your performance baseline, the real work begins: drilling down into the "CPU Usage" module. Instead of looking at the high-level graph, switch your view mode from "Timeline" to "Hierarchy".
The Hierarchy view displays your frames as a nested list, sorted by "Self" time (the time spent in a specific method, excluding its children). This is your most powerful diagnostic tool. By default, you should sort by the "GC Alloc" and "Time ms" columns to see what is causing memory pressure and frame spikes.
Isolating Heavy Scripts
When you expand a sample, you are tracing the execution path of your code. For instance, if you see high overhead under PlayerController.Update, you can drill down through the calls:
// Profiler trace might show:
// PlayerController.Update() -> CalculatePhysics() -> ComplexMathFunction()
If ComplexMathFunction() shows a high percentage in the "Self" column, you know exactly where to optimize. Avoid the trap of guessing; the Profiler provides empirical data. If you see deep call stacks, check for:
- Redundant loops: Are you iterating through large collections inside
Update()? - Expensive API calls: Are you calling
GetComponent()orFind()inside a loop? - Unexpected GC Allocations: Is a method creating new objects (like strings or lists) every frame, triggering the Garbage Collector?
Practical Workflow
Start by recording a representative gameplay session. Focus on the spikes in the CPU graph. Click the spike, switch to the Hierarchy view, and expand the Scripts category. By clicking on a method, the Profiler will highlight the exact script in your project, allowing you to jump straight to the source code. If the method name is obfuscated or you see Native code taking up time, ensure you have "Development Build" and "Autoconnect Profiler" enabled to get the most accurate symbol data.
Key Takeaway: Use the Hierarchy view to sort by "Self" time and "GC Alloc" to eliminate guesswork and focus your optimization efforts on the specific methods stalling your frame rate.