docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct ProfilingScope

    RAII scope that calls Begin(CommandBuffer) on construction and End(CommandBuffer) on disposal, ensuring markers are always balanced. Use in a using statement to guarantee Dispose() is called.

    Implements
    IDisposable
    Inherited Members
    ValueType.Equals(object)
    ValueType.GetHashCode()
    ValueType.ToString()
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: UnityEngine.Rendering
    Assembly: Unity.RenderPipelines.Core.Runtime.dll
    Syntax
    [IgnoredByDeepProfiler]
    public struct ProfilingScope : IDisposable
    Remarks

    This struct is a no-op in non-development Players.

    Constructors

    ProfilingScope(BaseCommandBuffer, ProfilingSampler)

    Creates a profiling scope that records markers into cmd as well as inline on the CPU.

    Declaration
    public ProfilingScope(BaseCommandBuffer cmd, ProfilingSampler sampler)
    Parameters
    Type Name Description
    BaseCommandBuffer cmd

    Command buffer to receive the GPU-visible begin/end markers.

    ProfilingSampler sampler

    The sampler that provides the underlying marker. May be null; the scope is a no-op in that case.

    Remarks

    Do not use with a named CommandBuffer. A named command buffer inserts its own scope marker on execution, which orphans the markers added here: the begin and end appear inside different named-buffer execution brackets and will be mismatched in the Profiler timeline.

    ProfilingScope(CommandBuffer, ProfilingSampler)

    Creates a profiling scope that records markers into cmd as well as inline on the CPU.

    Declaration
    public ProfilingScope(CommandBuffer cmd, ProfilingSampler sampler)
    Parameters
    Type Name Description
    CommandBuffer cmd

    Command buffer to receive the GPU-visible begin/end markers.

    ProfilingSampler sampler

    The sampler that provides the underlying marker. May be null; the scope is a no-op in that case.

    Remarks

    Do not use with a named CommandBuffer. A named command buffer inserts its own scope marker on execution, which orphans the markers added here: the begin and end appear inside different named-buffer execution brackets and will be mismatched in the Profiler timeline.

    ProfilingScope(CommandBuffer, ProfilingSampler, Object)

    Creates a profiling scope that records markers into cmd with a Unity Object context associated with the sample.

    Declaration
    public ProfilingScope(CommandBuffer cmd, ProfilingSampler sampler, Object contextObject)
    Parameters
    Type Name Description
    CommandBuffer cmd

    Command buffer to receive the GPU-visible begin/end markers.

    ProfilingSampler sampler

    The sampler that provides the underlying marker. May be null; the scope is a no-op in that case.

    Object contextObject

    Unity Object (e.g. Texture, Mesh, Material) to associate with this sample. The Profiler displays it in the sample hierarchy.

    Remarks

    Do not use with a named CommandBuffer. A named command buffer inserts its own scope marker on execution, which orphans the markers added here.

    ProfilingScope(ProfilingSampler)

    Creates a profiling scope without a command buffer (inline CPU profiling only).

    Declaration
    public ProfilingScope(ProfilingSampler sampler)
    Parameters
    Type Name Description
    ProfilingSampler sampler

    The sampler that provides the underlying marker. May be null; the scope is a no-op in that case.

    ProfilingScope(ProfilingSampler, Object)

    Creates an inline CPU-only profiling scope with a Unity Object context associated with the sample. No command buffer is involved; the marker is emitted directly on the CPU timeline.

    Declaration
    public ProfilingScope(ProfilingSampler sampler, Object contextObject)
    Parameters
    Type Name Description
    ProfilingSampler sampler

    The sampler that provides the underlying marker. May be null; the scope is a no-op in that case.

    Object contextObject

    Unity Object (e.g. Texture, Mesh, Material) to associate with this sample. The Profiler displays it in the sample hierarchy.

    Methods

    Dispose()

    Ends the profiling scope by calling End(CommandBuffer). Safe to call multiple times.

    Declaration
    public void Dispose()

    Implements

    IDisposable

    Extension Methods

    AnalyticsUtils.ToNestedColumnWithDefault<T>(T, T, bool)
    AnalyticsUtils.ToNestedColumn<T>(T, bool)
    AnalyticsUtils.ToNestedColumn<T>(T, T)
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)