Course contentsShow
← Unity Game Development
Lesson 209 of 8283. Physics and InteractionFree lesson

Analyzing Physics Performance with the Profiler

Learners will identify physics-related bottlenecks by analyzing frame time spikes and CPU usage within the Unity Profiler.

In this lesson, you will learn how to identify physics-related performance bottlenecks by using the Unity Profiler to track CPU spikes and sub-system usage.

When your game experiences sudden "stutters" or frame rate drops, the culprit is often the physics simulation. Because physics calculations happen on every FixedUpdate tick, an overly complex scene or poorly optimized colliders can quickly overwhelm your CPU.

Using the Profiler to Spot Spikes

To investigate, open the Profiler window (Window > Analysis > Profiler). Ensure the CPU Usage module is enabled.

  1. Record a Session: Press the "Record" button and play your game, specifically triggering the areas where you notice lag.
  2. Find the Spikes: Look at the CPU usage chart. Tall, jagged spikes indicate frames where the engine took significantly longer to process.
  3. Isolate Physics: Click on the CPU Usage timeline. In the bottom panel, switch the view to Hierarchy and sort by the "Time ms" column. Look for the label Physics.Simulate.

If Physics.Simulate consumes a large portion of your frame time, your physics engine is struggling. You can expand this tag to see sub-processes like Physics.Processing (collision detection) or Physics.Contacts (the number of active collisions).

Interpreting the Data

If you see high values in Physics.Processing, it is a clear sign that your scene contains too many overlapping triggers or complex mesh colliders. For example, having hundreds of high-poly mesh colliders interacting simultaneously is a common performance killer.

You can cross-reference these spikes with your game code. If you notice a spike every time a specific object enters a trigger volume, you might find that you are accidentally running expensive calculations inside OnTriggerStay.

// Expensive: Doing heavy logic in OnTriggerStay every fixed frame
void OnTriggerStay(Collider other) {
    // If this runs for 50 objects simultaneously, your Profiler 
    // will show a spike in Physics.Processing.
    PerformHeavyCalculation(); 
}

By identifying which specific frames cause the Physics.Simulate spike, you can determine if you need to simplify your colliders, adjust your physics layers, or optimize your collision logic.

Key Takeaway: Use the CPU Usage Profiler to isolate the Physics.Simulate tag; if it is spiking, focus on reducing collider complexity and minimizing logic inside your collision callbacks.