Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

ProfilerMarker.Auto

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public AutoScope Auto();

Declaration

public AutoScope Auto(Object contextUnityObject);

Declaration

public AutoScope Auto(string metadata);

Parameters

Parameter Description
contextUnityObject Unity object associated with the profiling operation.
metadata Additional contextual metadata string to attach to the profiling sample.

Returns

AutoScope IDisposable struct which calls Begin and End automatically.

Description

Creates a helper struct for the scoped using blocks.

Begin is called in the constructor and End in the Dispose method.

When a contextUnityObject is provided, the Profiler will associate the profiling sample with the specified Unity object. This allows you to see which specific objects are associated with performance samples in the Profiler window, making it easier to identify performance bottlenecks related to specific GameObjects, Components, or other Unity objects.

When metadata is provided, it attaches additional contextual information to the profiling sample. This string appears in the Profiler window alongside the marker name, allowing you to track different execution paths or parameter values without creating separate markers. This is particularly useful for profiling methods that handle different data or scenarios.

Note: Auto is thread safe and can be used in jobified code.

using Unity.Profiling;
using UnityEngine;

public class MySystemClass : MonoBehaviour { static ProfilerMarker s_SimulatePerfMarker = new ProfilerMarker("MySystem.Simulate"); static ProfilerMarker s_ProcessItemPerfMarker = new ProfilerMarker("MySystem.ProcessItem");

public void UpdateLogic() { // Basic usage using (s_SimulatePerfMarker.Auto()) { // ... }

// Associate the profiler sample with a specific object using (s_SimulatePerfMarker.Auto(this)) { // ... } }

public void ProcessItem(string itemType) { // Add metadata to distinguish different code paths using (s_ProcessItemPerfMarker.Auto(itemType)) { // Process based on itemType // The metadata helps identify which type is causing performance issues } } }