title: Unity TileMaps: How do I return the Layer name, Tag, or other identifying information of a tile that occupies a particular Vector3 location?
body: <p>I am making a game that takes place on a Tile Map. Each Tile is 32x32, and when characters on my map move, they move 32 pixels at a time.</p>
  
  <p>What I would like to do is examine a Vector3 location and have it return what type of tile it is. Like, just the layer is fine.</p>
  
  <p>My map has 5 layers:
  1. Floor: everyone can walk on this.
  2. Sink Floor: For tiles that are swamp or shallow water, the Player's sprite changes to an alternate version where they are sunk up to their hips while on the tile.
  3. Low Block: Things like Pits, Deep Water. Most characters are blocked unless they have flying.
  4. Block: Walls. They block all characters.
  5. Door: Sometimes blocks, sometimes passes through, depends if the player has the right key.</p>
  
  <p>here is my Character class, that the other characters inherit from.</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public abstract class Character : MonoBehaviour
  {
      public int health, wounds;
      public List&lt;Sprite&gt; frame;
  
      protected BoxCollider2D boxCollider;
  
      protected virtual void Start()
      {
          boxCollider = GetComponent&lt;BoxCollider2D&gt;();
      }
  
      protected virtual void MoveNorth()
      { //moves the character 1 tile north
          Vector3 oldLoc = this.gameObject.transform.position;
          Vector3 newLoc = new Vector3(oldLoc.x, oldLoc.y + (Game.instance.TILESIZE / 100f), oldLoc.z);        
          this.gameObject.transform.position = newLoc;
      }
  
      protected virtual void MoveWest()
      {//moves the character 1 tile west
          Vector3 oldLoc = this.gameObject.transform.position;
          Vector3 newLoc = new Vector3(oldLoc.x - (Game.instance.TILESIZE / 100f), oldLoc.y, oldLoc.z);        
          this.gameObject.transform.position = newLoc;
      }
  
      protected virtual void MoveSouth()
      {//moves the character 1 tile south
          Vector3 oldLoc = this.gameObject.transform.position;
          Vector3 newLoc = new Vector3(oldLoc.x, oldLoc.y - (Game.instance.TILESIZE / 100f), oldLoc.z);
          this.gameObject.transform.position = newLoc;
      }
  
      protected virtual void MoveEast()
      {//moves the character 1 tile east
          Vector3 oldLoc = this.gameObject.transform.position;
          Vector3 newLoc = new Vector3(oldLoc.x + (Game.instance.TILESIZE / 100f), oldLoc.y, oldLoc.z);
          this.gameObject.transform.position = newLoc;
      }
  
      protected virtual void WarpTo(int x, int y)
      {
          //Warps Sprite to specified tile.
          float trueTileSize = Game.instance.TILESIZE / 100f;
          float trueX = (x * trueTileSize + (trueTileSize / 2f));
          float trueY = (y * trueTileSize + (trueTileSize / 2f));
          this.gameObject.transform.position = new Vector3(trueX, trueY, 0f);
          Debug.Log("Tile size = " + trueTileSize + "   X: " + trueX + "   y: "+ trueY);
      }
  }
  </code></pre>
  
  <p>The plan is to insert code that will detect what tile is at NewLoc and then determine whether or not the move can be completed. I also want to detect what tile my characters are standing on so that I can change the sprite to the "Wading" version, but I don't have code for that yet.</p>
  
  <p>I am aware that this is probably basic. I have spent a lot of time searching and researching, but either I am over-thinking what I am trying to do, or I am just plain not understanding the answers I have been finding.</p>
  
  <p>I think that the solution is probably related to TileMap.GetTile, but I just do not understand how to use it, and I cannot seem to find an example using it in a way that I understand.</p>
  
  <p>Any help is appreciated!</p>
  
  <p>Update, after Ignacio Alorre's advice:
  Here is my Map:
  <a href="https://i.stack.imgur.com/3ZLlO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3ZLlO.jpg" alt="Full map with all layers"></a></p>
  
  <p>Here is just "SinkFloor" layer:
  <a href="https://i.stack.imgur.com/zCGjR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zCGjR.jpg" alt="Map with one layer (and the player)"></a></p>
  
  <p>Here are the settings for that layer:
  <a href="https://i.stack.imgur.com/kPYMq.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kPYMq.jpg" alt="Sink Floor Unity settings"></a></p>
  
  <p>and here is my new Character abstract class, with my attempt at adding the CheckTile function:</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.Tilemaps;
  
  public abstract class Character : MonoBehaviour
  {
  public int health, wounds;
  public List&lt;Sprite&gt; frame;
  
  protected BoxCollider2D boxCollider;
  
  protected virtual void Start()
  {
      boxCollider = GetComponent&lt;BoxCollider2D&gt;();
  }
  
  protected virtual void MoveNorth()
  { //moves the character 1 tile north
      Vector3 oldLoc = this.gameObject.transform.position;
      Vector3 newLoc = new Vector3(oldLoc.x, oldLoc.y + 
  (Game.instance.TILESIZE / 100f), oldLoc.z);
      checkTile(newLoc);
      this.gameObject.transform.position = newLoc;
  }
  
  protected virtual void MoveWest()
  {//moves the character 1 tile west
      Vector3 oldLoc = this.gameObject.transform.position;
      Vector3 newLoc = new Vector3(oldLoc.x - (Game.instance.TILESIZE / 
  100f), oldLoc.y, oldLoc.z);        
      this.gameObject.transform.position = newLoc;
  }
  
  protected virtual void MoveSouth()
  {//moves the character 1 tile south
      Vector3 oldLoc = this.gameObject.transform.position;
      Vector3 newLoc = new Vector3(oldLoc.x, oldLoc.y - 
  (Game.instance.TILESIZE / 100f), oldLoc.z);
      this.gameObject.transform.position = newLoc;
  }
  
  protected virtual void MoveEast()
  {//moves the character 1 tile east
      Vector3 oldLoc = this.gameObject.transform.position;
      Vector3 newLoc = new Vector3(oldLoc.x + (Game.instance.TILESIZE / 
  100f), oldLoc.y, oldLoc.z);
      this.gameObject.transform.position = newLoc;
  }
  
  protected virtual void WarpTo(int x, int y)
  {
      //Warps Sprite to specified tile.
      float trueTileSize = Game.instance.TILESIZE / 100f;
      float trueX = (x * trueTileSize + (trueTileSize / 2f));
      float trueY = (y * trueTileSize + (trueTileSize / 2f));
      this.gameObject.transform.position = new Vector3(trueX, trueY, 0f);
      Debug.Log("Tile size = " + trueTileSize + "   X: " + trueX + "   y: "+ 
  trueY);
  }
  
  protected virtual int checkTile(Vector3 tileLoc)
  {
      RaycastHit hit;
      float distance = 1f;
      Vector3 dir = new Vector3(0, -1, 0);        
      //Vector3 locAdjusted = new Vector3(tileLoc.x, tileLoc.y, tileLoc.z - 
      //0.5f);
  
      int layer = -1;
  
      if(Physics.Raycast(tileLoc, dir, out hit, distance))
      {
          layer = hit.collider.gameObject.layer;
          Debug.Log("Layer #: " + layer);
      }       
  
      return layer;
    }
  }
  </code></pre>
  
  <p>What is supposed to happen at this stage is that whenever my player (who inherits this class) moves up, checkTile(newLoc); fires and when the RayCast hits a collider, it should report that feat in the console, along with what the layer is.
  It is not.
  I have tried adjusting the rayCast origin above the layer I am looking at, which should at least return the Character, but it does not. I am thinking I need to look into Raycasting a bit closer to see if I can figure out how to do this.
  Once I get it to work, it should be EXACTLY what I need.</p>