Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

How to SetTile inside GetTileData ?

Discussion in '2D' started by diego-vieira, Sep 16, 2019.

  1. diego-vieira


    Mar 27, 2015
    Hey guys, I am trying to create a Tile using the new Tilemap system, that when a paint this tile automatically paints other 2 tiles for me.

    Think about a tree, I paint the bottom part of the tree and the Tile paints the trunk and the top for me automatically.

    I am trying to do this inside the GetTileData method, but everytime I call tilemap.SetTile inside this method and drag the Tile to the pallete Unity crashes.

    Anyone knows if this is a bug or if I can't do this ?

    I tried using this code (trunkTile and topTile are common TileBases):
    Code (CSharp):
    1. public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
    2.      {
    3.          Tilemap tilemapInstance = tilemap.GetComponent<Tilemap>();
    4.          tilemapInstance.SetTile(new Vector3Int(position.x, position.y - 1, position.z), trunkTile);
    5.          tilemapInstance.SetTile(new Vector3Int(position.x, position.y - 2, position.z), topTile);
    6.          base.GetTileData(position, tilemap, ref tileData);
    7.      }