# TerrainPaintTool<T>

> Base class for terrain painting tools.

## Definition

* **Type:** Class
* **Namespace:** [UnityEditor.TerrainTools](/engine/6000.5/script-reference/unityeditor/terraintools.md)
* **Assembly:** UnityEditor
* **Inherits from:** [ScriptableSingleton\<T>](/engine/6000.5/script-reference/unityeditor/scriptablesingleton1.md)

```csharp
public abstract class TerrainPaintTool<T> : ScriptableSingleton<T> where T : TerrainPaintTool<T>
```

## Remarks

Derive from this class to implement your own terrain painting tools.

## Examples

```csharp
using UnityEngine;
using UnityEditor;
using UnityEngine.TerrainTools;

namespace UnityEditor.TerrainTools
{
    public class MyPaintHeightTool : TerrainPaintTool<MyPaintHeightTool>
    {
        Material m_Material = null;
        Material GetPaintMaterial()
        {
            if (m_Material == null)
                m_Material = new Material(Shader.Find("Hidden/Terrain/PaintHeight"));
            return m_Material;
        }

        public override string GetName()
        {
            return "My Paint Height Tool";
        }

        public override string GetDescription()
        {
            return "Left click to raise.\n\nHold shift and left click to lower.";
        }

        public override void OnRenderBrushPreview(Terrain terrain, IOnSceneGUI editContext)
        {
            TerrainPaintUtilityEditor.ShowDefaultPreviewBrush(terrain, editContext.brushTexture, editContext.brushSize);
        }

        public override bool OnPaint(Terrain terrain, IOnPaint editContext)
        {
            Material mat = TerrainPaintUtility.GetBuiltinPaintMaterial();

            float rotationDegrees = 0.0f;
            BrushTransform brushXform = TerrainPaintUtility.CalculateBrushTransform(terrain, editContext.uv, editContext.brushSize, rotationDegrees);
            PaintContext paintContext = TerrainPaintUtility.BeginPaintHeightmap(terrain, brushXform.GetBrushXYBounds());

            // apply brush
            Vector4 brushParams = new Vector4(editContext.brushStrength * 0.01f, 0.0f, 0.0f, 0.0f);
            mat.SetTexture("_BrushTex", editContext.brushTexture);
            mat.SetVector("_BrushParams", brushParams);
            TerrainPaintUtility.SetupTerrainToolMaterialProperties(paintContext, brushXform, mat);

            Graphics.Blit(paintContext.sourceRenderTexture, paintContext.destinationRenderTexture, mat, (int)TerrainBuiltinPaintMaterialPasses.RaiseLowerHeight);

            TerrainPaintUtility.EndPaintHeightmap(paintContext, "Terrain Paint - MyPaintHeightTool");
            return false;
        }
    }
}
```

## Methods

| Method                                                                                                                     | Description                                                                                                                                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [GetDescription](/engine/6000.5/script-reference/unityeditor/terraintools/terrainpainttool1/getdescription.md)             | Retrieves the description of the custom terrain tool.                                                                                                                                                                                       |
| [GetName](/engine/6000.5/script-reference/unityeditor/terraintools/terrainpainttool1/getname.md)                           | Retrieves the name of the custom terrain tool.                                                                                                                                                                                              |
| [OnDisable](/engine/6000.5/script-reference/unityeditor/terraintools/terrainpainttool1/ondisable.md)                       | Called when the tool is destroyed.                                                                                                                                                                                                          |
| [OnEnable](/engine/6000.5/script-reference/unityeditor/terraintools/terrainpainttool1/onenable.md)                         | Called when the tool is created.                                                                                                                                                                                                            |
| [OnEnterToolMode](/engine/6000.5/script-reference/unityeditor/terraintools/terrainpainttool1/onentertoolmode.md)           | Called when the tool is activated.                                                                                                                                                                                                          |
| [OnExitToolMode](/engine/6000.5/script-reference/unityeditor/terraintools/terrainpainttool1/onexittoolmode.md)             | Called when the tool becomes inactive.                                                                                                                                                                                                      |
| [OnInspectorGUI](/engine/6000.5/script-reference/unityeditor/terraintools/terrainpainttool1/oninspectorgui.md)             | Custom terrain tool OnInspectorGUI callback.                                                                                                                                                                                                |
| [OnPaint](/engine/6000.5/script-reference/unityeditor/terraintools/terrainpainttool1/onpaint.md)                           | Custom terrain tool paint callback.                                                                                                                                                                                                         |
| [OnRenderBrushPreview](/engine/6000.5/script-reference/unityeditor/terraintools/terrainpainttool1/onrenderbrushpreview.md) | Use this method to implement custom tool preview and UI behavior that will only render while the mouse is within the [SceneView](/engine/6000.5/script-reference/unityeditor/sceneview.md) bounds or while you're actively using this tool. |
| [OnSceneGUI](/engine/6000.5/script-reference/unityeditor/terraintools/terrainpainttool1/onscenegui.md)                     | Custom terrain tool OnSceneGUI callback.                                                                                                                                                                                                    |

## Inheritance

**Inherited Members:**

* [ScriptableSingleton\<T>.Save(bool)](/engine/6000.5/script-reference/unityeditor/scriptablesingleton1/save.md)
* [ScriptableSingleton\<T>.GetFilePath()](/engine/6000.5/script-reference/unityeditor/scriptablesingleton1/getfilepath.md)
* [ScriptableSingleton\<T>.instance](/engine/6000.5/script-reference/unityeditor/scriptablesingleton1/instance.md)
* [ScriptableObject.CreateInstance(string)](/engine/6000.5/script-reference/unityengine/scriptableobject/createinstance.md#createinstance\(string\))
* [ScriptableObject.CreateInstance(Type)](/engine/6000.5/script-reference/unityengine/scriptableobject/createinstance.md#createinstance\(type\))
* [ScriptableObject.CreateInstance\<T>()](/engine/6000.5/script-reference/unityengine/scriptableobject/createinstance.md)
* [Object.GetEntityId()](/engine/6000.5/script-reference/unityengine/object/getentityid.md)
* [Object.GetHashCode()](/engine/6000.5/script-reference/unityengine/object/gethashcode.md)
* [Object.InstantiateAsync\<T>(T)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Transform)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Vector3, Quaternion)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Transform, Vector3, Quaternion)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Vector3, Quaternion)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, Vector3, Quaternion)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, InstantiateParameters, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, InstantiateParameters, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Vector3, Quaternion, InstantiateParameters, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Vector3, Quaternion, InstantiateParameters, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>, InstantiateParameters, CancellationToken)](/engine/6000.5/script-reference/unityengine/object/instantiateasync.md)
* [Object.Instantiate(Object, Vector3, Quaternion)](/engine/6000.5/script-reference/unityengine/object/instantiate.md#instantiate\(object-vector3-quaternion\))
* [Object.Instantiate(Object, Vector3, Quaternion, Transform)](/engine/6000.5/script-reference/unityengine/object/instantiate.md#instantiate\(object-vector3-quaternion-transform\))
* [Object.Instantiate(Object)](/engine/6000.5/script-reference/unityengine/object/instantiate.md#instantiate\(object\))
* [Object.Instantiate(Object, Scene)](/engine/6000.5/script-reference/unityengine/object/instantiate.md#instantiate\(object-scene\))
* [Object.Instantiate\<T>(T, InstantiateParameters)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion, InstantiateParameters)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate(Object, Transform)](/engine/6000.5/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform\))
* [Object.Instantiate(Object, Transform, bool)](/engine/6000.5/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform-bool\))
* [Object.Instantiate\<T>(T)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion, Transform)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Transform)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Transform, bool)](/engine/6000.5/script-reference/unityengine/object/instantiate.md)
* [Object.Destroy(Object, float)](/engine/6000.5/script-reference/unityengine/object/destroy.md)
* [Object.DestroyImmediate(Object, bool)](/engine/6000.5/script-reference/unityengine/object/destroyimmediate.md)
* [Object.FindObjectsByType(Type)](/engine/6000.5/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytype\(type\))
* [Object.FindObjectsByType(Type, FindObjectsInactive)](/engine/6000.5/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytype\(type-findobjectsinactive\))
* [Object.DontDestroyOnLoad(Object)](/engine/6000.5/script-reference/unityengine/object/dontdestroyonload.md)
* [Object.FindAnyObjectByType\<T>()](/engine/6000.5/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytypet\(\))
* [Object.FindAnyObjectByType\<T>(FindObjectsInactive)](/engine/6000.5/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytypet\(findobjectsinactive\))
* [Object.FindObjectsByType\<T>()](/engine/6000.5/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytypet\(\))
* [Object.FindObjectsByType\<T>(FindObjectsInactive)](/engine/6000.5/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytypet\(findobjectsinactive\))
* [Object.FindAnyObjectByType(Type)](/engine/6000.5/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytype\(type\))
* [Object.FindAnyObjectByType(Type, FindObjectsInactive)](/engine/6000.5/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytype\(type-findobjectsinactive\))
* [Object.ToString()](/engine/6000.5/script-reference/unityengine/object/tostring.md)
* [Object.name](/engine/6000.5/script-reference/unityengine/object/name.md)
* [Object.hideFlags](/engine/6000.5/script-reference/unityengine/object/hideflags.md)

### Operators

| Operator                                                                           | Description                                                             |
| ---------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [operator ==](/engine/6000.5/script-reference/unityengine/object/op-equality.md)   | Compares two object references to see if they refer to the same object. |
| [bool](/engine/6000.5/script-reference/unityengine/object/op-implicit.md)          | Determines whether the object exists.                                   |
| [operator !=](/engine/6000.5/script-reference/unityengine/object/op-inequality.md) | Compares if two objects refer to a different object.                    |
