Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Auto

Creates a helper struct for the scoped using blocks.
Read time 4 minutesLast updated 5 days ago

Definition

Auto()

Creates a helper struct for the scoped using blocks.
public ProfilerMarker.AutoScope Auto()

Returns

Type

Description

AutoScopeIDisposable struct which calls ProfilerMarker.Begin and ProfilerMarker.End automatically.

Remarks

ProfilerMarker.Begin is called in the constructor and ProfilerMarker.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: ProfilerMarker.Auto is thread safe and can be used in jobified code.

Examples

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 } }}

Auto(Object)

Creates a helper struct for the scoped using blocks.
public ProfilerMarker.AutoScope Auto(Object contextUnityObject)

Parameters

contextUnityObject

Unity object associated with the profiling operation.

Returns

Type

Description

AutoScopeIDisposable struct which calls ProfilerMarker.Begin and ProfilerMarker.End automatically.

Remarks

ProfilerMarker.Begin is called in the constructor and ProfilerMarker.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: ProfilerMarker.Auto is thread safe and can be used in jobified code.

Examples

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 } }}

Auto(string)

Creates a helper struct for the scoped using blocks.
public ProfilerMarker.AutoScope Auto(string metadata)

Parameters

metadata

Additional contextual metadata string to attach to the profiling sample.

Returns

Type

Description

AutoScopeIDisposable struct which calls ProfilerMarker.Begin and ProfilerMarker.End automatically.

Remarks

ProfilerMarker.Begin is called in the constructor and ProfilerMarker.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: ProfilerMarker.Auto is thread safe and can be used in jobified code.

Examples

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 } }}