Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Changing data inside a custom tile on tilemap without affecting the whole asset

Discussion in '2D' started by unity_sy_0Kh3suiuidw, Jun 10, 2023.

  1. unity_sy_0Kh3suiuidw

    unity_sy_0Kh3suiuidw

    Joined:
    Aug 13, 2020
    Posts:
    1
    I have a custom tile with isEmpty. When I change it via
    Code (CSharp):
    1. GetTile<MyCustomTile>(myPosition).isEmpty = false;
    it changes the whole same tile in the tilemap.
    I know however, that changing color of a tile through SetColor will change only specified tile so I was assuming unity do have reference to each of them.

    how am I supposed to do it ?, or is it just not how custom tile supposed to be used ?
     
  2. vonchor

    vonchor

    Joined:
    Jun 30, 2009
    Posts:
    238
    Unless you use a third-party solution, all positions on a tilemap where you place a tile all use the same tile for initial data (when GetTileData is called).

    When you use Tilemap.SetColor it affects only the tilemap's internal data. In contrast, if you change a field in a tile reference that you've obtained with GetTile then the Tile asset (a scriptable object subclass) itself is changed, affecting ALL positions where you've placed that tile.

    TLDR; the stock Tilemap system doesn't support fields in a tile which will only affect one single position.

    Hope that helps.
     
    unity_sy_0Kh3suiuidw likes this.
  3. karderos

    karderos

    Joined:
    Mar 28, 2023
    Posts:
    376
    you have to refresh all tiles, after the tile is place it is drawn and set in stone until you refresh that position again