How to place object only if it is adjacent to other objects in grid?

I have grid set up to 128x128

When I press B the game enters Build Mode

In this mode I can press left click to place my object.

What is the best way to allow the player to only place the object if it’s adjacent to other object
For example, the above image is not allowed to place because the object is not adjacent.
The below is allow because it’s adjacent.

I use this extension to snap object into grid

Here is how I enable object to be placed

Thank you.

The only thing I can think of is to check if the tile is in collision with any other tiles…however that’s probably not a great solution as constantly checking collisions will affect performance. Sorry, wish I could be of more help!

Thanks, your suggestion gives me some hint.

I will try to fix it.

You might also be able to check the distance between the objects, rather than using a collision check.