Custom Profiling Blocks with Profiler.BeginSample
Locating specific code bottlenecks in Unity’s Profiler can be tricky when logic is grouped inside standard engine blocks.
The Tip: Locating specific code bottlenecks in Unity’s Profiler can be tricky when logic is grouped inside standard engine blocks.
How to Use: Wrap suspicious logic in Profiler.BeginSample("Sample Name") and Profiler.EndSample(). Your custom sample will appear directly within the Profiler hierarchy view.
using UnityEngine;
using UnityEngine.Profiling;
public class CustomProfilerMarker : MonoBehaviour
{
private void Update()
{
Profiler.BeginSample("Custom Pathfinding Search");
// Pathfinding calculation logic
Profiler.EndSample();
}
}
Article complete?
20 XP lands automatically when you reach the end, and it counts toward today's quests.
Next level
Shader Graph Basics for 2D GamesGame Dev Articles · 1 min · +20 XPRate this article
Comments
Comments are held for moderation before appearing publicly.