Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Using prefab brush in tilemap, function HasTile returns null

Discussion in '2D' started by jspink, Nov 20, 2018.

  1. jspink

    jspink

    Joined:
    Dec 16, 2015
    Posts:
    2
    I followed an example to create a prefab brush because I wanted to add a script to a tile. It seemed to work OK and I can select my new brush and paint with it, but in the script if I check the tile position where I've used the prefab brush (using the HasTile method), it returns null. If I do a similar check for other tiles painted using the default brush, it works OK and returns the name of the tile.

    Am I doing something wrong here or is it not possible to do what I want? I've put some example code below

    Code (CSharp):
    1.  
    2. Vector3Int cell = new Vector3Int(0, 0, 0);
    3. Tilemap tileMap;
    4.  
    5. tileMap = FindObjectOfType<Tilemap>();
    6. cell.x = 0; cell.y = 0;
    7. if (tileMap.HasTile(cell))
    8.     Debug.Log("tile at 0,0   = " + tileMap.GetTile(cell).name);
    9. else
    10.     Debug.Log("tile at 0,0   = null");
    11.  
     
  2. emalmud

    emalmud

    Joined:
    Mar 5, 2014
    Posts:
    7
    bump! I need this answer as well!

    Im trying to have a prefab check for the tiles around it by position and they all come back null
     
  3. scloutier752

    scloutier752

    Joined:
    Feb 7, 2017
    Posts:
    4
    Same thing here, I guess it is pretty easy for someone knowing the answer?
     
  4. kukurenaiz

    kukurenaiz

    Joined:
    Sep 12, 2017
    Posts:
    57
    Prefab Brush as far as I can tell only paints the prefab aligned to the grid, it creates a new GameObject for each one, it is not a tile in the tilemap.