# BeginPaintTexture(Terrain, Rect, TerrainLayer, int, bool)

> Helper function to set up a PaintContext for modifying the alphamap of one or more Terrain tiles.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.TerrainTools](/engine/6000.7/script-reference/unityengine/terraintools.md)
* **Assembly:** UnityEngine.TerrainModule

```csharp
public static PaintContext BeginPaintTexture(Terrain terrain, Rect boundsInTerrainSpace, TerrainLayer inputLayer, int extraBorderPixels = 0, bool fillOutsideTerrain = true)
```

### Parameters

**** (\[Terrain]\(/engine/6000.7/script-reference/unityengine/terrain)): Reference Terrain tile.**** (\[Rect]\(/engine/6000.7/script-reference/unityengine/rect)): The region in terrain space to edit.**** (\[TerrainLayer]\(/engine/6000.7/script-reference/unityengine/terrainlayer)): Selects the alphamap to paint.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): Number of extra border pixels required.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Whether to fill empty space outside of Terrain tiles with data from the nearest tile.

### Returns

| Type                                                                                     | Description                                                                  |
| ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| [PaintContext](/engine/6000.7/script-reference/unityengine/terraintools/paintcontext.md) | PaintContext containing the combined alphamap data for the specified region. |

### Remarks

BeginPaintTexture identifies all of the alphamap pixels that are within `extraBorderPixels` of the bounds rectangle. The search is performed across adjacent connected Terrain tiles. The pixels are collected into a temporary render texture and stored in [\_sourceRenderTexture](/engine/6000.7/script-reference/unityengine/terraintools/paintcontext/sourcerendertexture.md).

After calling this function, you may modify the alphamap by writing the new values into [\_destinationRenderTexture](/engine/6000.7/script-reference/unityengine/terraintools/paintcontext/destinationrendertexture.md). Then, you may complete the modification by calling [TerrainPaintUtility.EndPaintTexture](/engine/6000.7/script-reference/unityengine/terraintools/terrainpaintutility/endpainttexture.md) to copy the modified data back to the Terrain tiles. Alteratively, you may cancel the modification by calling [TerrainPaintUtility.ReleaseContextResources](/engine/6000.7/script-reference/unityengine/terraintools/terrainpaintutility/releasecontextresources.md) to release the RenderTexture resources.

Additional Resources: [TerrainPaintUtility.EndPaintTexture](/engine/6000.7/script-reference/unityengine/terraintools/terrainpaintutility/endpainttexture.md), [PaintContext](/engine/6000.7/script-reference/unityengine/terraintools/paintcontext.md)
