Version: Unity 6.4 (6000.4)
Language : English
Custom tiles and brushes
Create a custom brush that runs a script

Create a custom tile that runs a script

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.

For example, you can script tiles to change how they look based on neighboring spritesA 2D graphic objects. If you are used to working in 3D, Sprites are essentially just standard textures but there are special techniques for combining and managing sprite textures for efficiency and convenience during development. More info
See in Glossary
, 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 TilemapA GameObject that allows you to quickly create 2D levels using tiles and a grid overlay. More info
    See in Glossary
    Extras package is installed in your project. For more information, refer to set up your project for 2D games.
  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 to paint with it.

For more information, refer to Scriptable tiles 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:

    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:

    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.

    [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 to paint with it.

Examples

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

Additional resources

Custom tiles and brushes
Create a custom brush that runs a script