Struggling to add and interact with colliders on isometric tilemap.

So I believe I have added the colliders correctly but I can’t seem to view or interact with my colliders on my isometric tilemap.
Here is the steps I followed:

  1. I added a custom physics shape to my sprite.
  2. My isometric rule tile’s default collider is set to sprite
  3. I added a TilemapCollider 2D component to my tilemap.
  4. When the player clicks (in building mode) it spawns a tile at said position then refreshes the tilemap’s collider.
myTilemap.SetTile(tilePos, selectedObject.Tile);
Debug.Log(myTilemap.GetComponent<TilemapCollider2D>().hasTilemapChanges); //returns true
myTilemap.GetComponent<TilemapCollider2D>().ProcessTilemapChanges();
  1. When the player then tries to click (in building selection mode) on the newly created tile.
RaycastHit hit;
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);                
if (Physics.Raycast(ray, out hit))
   {
      Debug.DrawRay(ray.origin, ray.direction, Color.red);
      Debug.Log(hit.collider.GetComponent<Sprite>());
   }
else
  {
     Debug.Log("No hit"); //returns this every time
   }

I had hoped by running Window>Analysis>Physics Debugger I could see the collider shapes in play mode but I cannot see anything.
If someone could point me to the step I’m missing it would be greatly appreciated.

Use 2D Physics queries not 3D Physics.

In 2D you cannot raycast into the screen because that doesn’t make sense. In 2D you use Physics2D.OverlapPoint via Camera.ScreenToWorldPoint.

Turn on Gizmos in the view otherwise you won’t see any. With the GameObject selected with the TilemapCollider2D you’ll see them.

Also, you can go into the “Project Settings > Physics 2D > Gizmos” and you can permanently turn on all 2D gizmos, ignoring any selection. Note that doing this can reduce performance in the Editor as it can end up drawing a lot of gizmos depending on your scene.

Thank you for info. That helps a lot.
I am now able to get the Tilemap Collider 2D component on the tilemap when I run.

var hit = Physics2D.OverlapPoint(worldPos);

But how do I subsequently get the sprite and cell position of the sprite from here?

To be honest, I would be confused as heck because Sprites have nothing to do with Physics and your post is asking how to detect a Collider only but I did just see that you’ve double posted here and you’re asking something else but not specifying that here.

Best to stick to one thread, don’t double post please. Let’s close this thread and continue over there.