# Create a custom tile that runs a script

> Create a prebuilt or custom scriptable tile that dynamically changes its look or the look of the tiles around it.

Scriptable tiles are tiles that dynamically change their appearance, or change the appearance of the tiles around them. Scriptable tiles are part of the [2D Tilemap Extras package](https://docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@latest/index.html?subfolder=/manual/).

For example, you can script tiles to change how they look based on neighboring sprites, or play animations.

You can do either the following:

* Add a prebuilt scriptable tile.
* Create a custom scriptable tile using the `TileBase` API.

## Add a prebuilt scriptable tile

To create a prebuilt scriptable tile, follow these steps:

1. Make sure the 2D Tilemap Extras package is installed in your project. For more information, refer to [set up your project for 2D games](/engine/6000.5/manual/unity2d/2d-game-development/setup-project-2d-game.md).
2. From the main menu, select **Assets** > **Create** > **2D** > **Tiles**.
3. Select a prebuilt scriptable tile.
4. Drag the tile from the **Project** window into a [tile palette](/engine/6000.5/manual/unity2d/tilemaps/create-tile-palette/assets.md) to paint with it.

For more information, refer to [Scriptable tiles](https://docs.unity3d.com/Packages/com.unity.2d.tilemap.extras@latest/index.html?subfolder=/manual/Tiles.html) in the 2D Tilemap Extras package documentation.

## Create a custom scriptable tile

Follow these steps:

1. To create a new C# script, from the main menu select **Assets** > **Create** > **MonoBehaviour script**.

2. Open the script and replace the code with a class that inherits from `UnityEngine.Tilemaps.TileBase`. For example:

   ```csharp
   using UnityEngine;
   using UnityEngine.Tilemaps;

   public class MyScriptableTile : TileBase
   {
   }
   ```

3. Implement the `GetTileData` method. This method determines the look of the new tile. For example:

   ```csharp
   public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
   {
       tileData.color = Color.white;
   }
   ```

4. To create instances of your tile as assets in your project, add a `CreateAssetMenu` attribute before the class declaration.

   ```csharp
   [CreateAssetMenu]
   public class MyScriptableTile : TileBase
   {
       ...
   }
   ```

5. Create an instance of the tile. For example in the previous example, from the main menu, select **Assets** > **My Scriptable Tile**.

6. Drag the tile from the **Project** window into a [tile palette](/engine/6000.5/manual/unity2d/tilemaps/create-tile-palette/assets.md) to paint with it.

## Examples

Refer to the following for examples of a custom scriptable tile:

* [`Tilemaps.TileBase.GetTileData`](/engine/6000.5/script-reference/unityengine/tilemaps/tilebase/gettiledata.md).
* [`Tilemaps.TileBase.RefreshTile`](/engine/6000.5/script-reference/unityengine/tilemaps/tilebase/refreshtile.md) for an example of using `RefreshTile` to determine which other tiles run their `GetTileData` method when you paint the tile.

## Additional resources

* [Tile Palette editor tools](/engine/6000.5/manual/unity2d/tilemaps/create-tile-palette/tile-palette-tools.md)
