“Rule Tiles: Floor/Wall Side Ceiling Appearing in Middle & Top/Bottom Tiles Missing with Custom RuleTile”

I am working with Rule Tiles in Unity 2D Tilemap. I created separate rule tiles for Floor and Wall, and each of them is placed in a separate Tilemap layer.

Both tiles also have ceiling/edge tiles that should appear only on the sides of the floor or wall. However, I am facing a problem during gameplay when I place tiles dynamically.

Problem 1:
When I place Floor or Wall tiles during gameplay, the ceiling/edge tiles appear in the middle instead of only on the sides.

Problem 2:
To fix this, I tried using a Custom RuleTile script, but then another issue appears.
When I use the custom RuleTile:

  • The top tile of the Floor does not appear.
  • The bottom tile of the Wall does not appear.

So basically:

  • Without the custom RuleTile → the ceiling/edge tiles appear in the wrong places (middle).
  • With the custom RuleTile → the correct top/bottom tiles for floor and wall are missing.

I want the tiles to behave like this:

  • Floor and Wall should detect each other as neighbors, even though they are on separate tilemaps.
  • The ceiling tiles should appear only on the sides, not in the middle.
  • The top of the floor and bottom of the wall should render correctly.

What is the correct way to handle this with Rule Tiles or a Custom RuleTile script?