# Handles.DrawingScope

> Disposable helper struct for automatically setting and reverting Handles.color and/or Handles.matrix.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEditor](/engine/6000.6/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule
* **Implements:** [IDisposable](https://learn.microsoft.com/dotnet/api/system.idisposable)

```csharp
public struct Handles.DrawingScope : IDisposable
```

## Remarks

This struct allows you to temporarily set the value of [Handles.color](/engine/6000.6/script-reference/unityeditor/handles/color.md) and/or [Handles.matrix](/engine/6000.6/script-reference/unityeditor/handles/matrix.md) inside of a block of code and automatically revert them to their previous values when the scope is exited.

## Examples

```csharp
using UnityEditor;
using UnityEngine;

// a custom editor that draws a labeled circle around the selected MeshRenderer in the scene view
[CustomEditor(typeof(MeshRenderer))]
public class MeshRendererEditor : Editor
{
    protected virtual void OnSceneGUI()
    {
        MeshRenderer meshRenderer = (MeshRenderer)target;

        // get an orientation pointing from the selected object to the camera
        Vector3 cameraToTarget = Camera.current.transform.position - meshRenderer.transform.position;
        Quaternion billboardOrientation = Quaternion.LookRotation(cameraToTarget, Camera.current.transform.up);

        // set the handle matrix to the target's position, oriented facing the camera
        Matrix4x4 matrix = Matrix4x4.TRS(meshRenderer.transform.position, billboardOrientation, Vector3.one);
        using (new Handles.DrawingScope(Color.magenta, matrix))
        {
            // draw a magenta circle around the selected object with a label at the top
            Vector3 size = meshRenderer.bounds.size;
            float radius = Mathf.Max(size.x, size.y, size.z);
            Handles.DrawWireArc(Vector3.zero, Vector3.forward, Vector3.right, 360f, radius);
            Handles.Label(Vector3.up * radius, meshRenderer.name);
        }
    }
}
```

## Constructors

| Constructor                                                                                                                                                       | Description                                                                                                                                                                                                                     |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [DrawingScope(UnityEngine.Color)](/engine/6000.6/script-reference/unityeditor/handles/drawingscope/ctor.md#drawingscope\(color\))                                 | Create a new DrawingScope and set [Handles.color](/engine/6000.6/script-reference/unityeditor/handles/color.md) and/or [Handles.matrix](/engine/6000.6/script-reference/unityeditor/handles/matrix.md) to the specified values. |
| [DrawingScope(UnityEngine.Color,UnityEngine.Matrix4x4)](/engine/6000.6/script-reference/unityeditor/handles/drawingscope/ctor.md#drawingscope\(color-matrix4x4\)) | Create a new DrawingScope and set [Handles.color](/engine/6000.6/script-reference/unityeditor/handles/color.md) and/or [Handles.matrix](/engine/6000.6/script-reference/unityeditor/handles/matrix.md) to the specified values. |
| [DrawingScope(UnityEngine.Matrix4x4)](/engine/6000.6/script-reference/unityeditor/handles/drawingscope/ctor.md#drawingscope\(matrix4x4\))                         | Create a new DrawingScope and set [Handles.color](/engine/6000.6/script-reference/unityeditor/handles/color.md) and/or [Handles.matrix](/engine/6000.6/script-reference/unityeditor/handles/matrix.md) to the specified values. |

## Properties

| Property                                                                                             | Description                                                                                                                                                                                                            |
| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [originalColor](/engine/6000.6/script-reference/unityeditor/handles/drawingscope/originalcolor.md)   | The value of [Handles.color](/engine/6000.6/script-reference/unityeditor/handles/color.md) at the time this [Handles.DrawingScope](/engine/6000.6/script-reference/unityeditor/handles/drawingscope.md) was created.   |
| [originalMatrix](/engine/6000.6/script-reference/unityeditor/handles/drawingscope/originalmatrix.md) | The value of [Handles.matrix](/engine/6000.6/script-reference/unityeditor/handles/matrix.md) at the time this [Handles.DrawingScope](/engine/6000.6/script-reference/unityeditor/handles/drawingscope.md) was created. |

## Methods

| Method                                                                                 | Description                                                                                                                                                                                                                                                                                                  |
| -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| [Dispose](/engine/6000.6/script-reference/unityeditor/handles/drawingscope/dispose.md) | Automatically reverts [Handles.color](/engine/6000.6/script-reference/unityeditor/handles/color.md) and [Handles.matrix](/engine/6000.6/script-reference/unityeditor/handles/matrix.md) to their values prior to entering the scope, when the scope is exited. You do not need to call this method manually. |
