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

Auto(Object)

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

Parameters

Parameter Description
contextUnityObject Unity object associated with the profiling operation.
metadata Additional contextual metadata string for the marker.

Description

Helper IDisposable struct for use with ProfilerMarker.Auto.

Use ProfilerMarker.Auto to enclose a piece of code you want to profile in using statement. Constructor of AutoScope calls ProfilerMarker.Begin and Dispose method - ProfilerMarker.End.

The contextUnityObject parameter associates the profiling sample with a specific Unity object, making it easier to identify which objects contribute to performance issues in the Profiler window.

The metadata parameter attaches additional contextual information to help distinguish different execution paths or parameter values without creating separate markers.

using Unity.Profiling;
using UnityEngine;

public class MySystemClass : MonoBehaviour { ProfilerMarker simulatePerfMarker = new ProfilerMarker("MySystem.Simulate"); ProfilerMarker processItemPerfMarker = new ProfilerMarker("MySystem.ProcessItem");

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

// With object context using (simulatePerfMarker.Auto(this)) { // ... } }

public void ProcessItem(string itemType) { // With metadata using (processItemPerfMarker.Auto(itemType)) { // ... } } }