Is it possible to have Rule Tiles change their rendering layer depending on what tile it is?

I’m currently using the Rule Tiles from the 2D Tilemap Extras package, which automatically change to a specific sprite whenever they’re next to other rule tiles. It’s super helpful when designing play areas, as I don’t have to pick each sprite individually to place, I can just draw and it looks good automatically.

However, I can’t figure out if I can have the rendering layer change as well as the sprite. I’m trying to get an effect where the player walks behind the wall and is hidden from the camera. For example, in Enter the Gungeon, the player can walk in front of the walls:

8631375--1160313--upload_2022-12-2_16-19-30.png

And behind the walls:

8631375--1160316--upload_2022-12-2_16-19-44.png

I can make my character walk in front of the wall like in the example, but I can’t figure out how to get him behind it without him overlapping, like down below:

8631375--1160319--upload_2022-12-2_16-20-24.png

Any idea how i can make this work with the rule tiles? Much appreciated.

The thing to modify isn’t the render layer but rather than Transparency Sort Axis.

What you want is “objects with a larger y-position are rendered behind objects smaller in y.” That’s what the Transparency Sort Axis does.

You need to
1. Assign/verify (0, 1, 0) is your transparency sort axis. If you’re using the 2D Renderer, this is on the 2D Renderer asset (see at top). If you’re not, then it’s within Edit > Project Settings > Graphics.

2. Move the items that sort against the character to an Individual Mode tilemap (see the TilemapRenderer - you don’t want Chunk mode), and set its Order/Layer to the SAME as the character. Now the character and items will sort against one another according to your sort axis.

3. Give those item sprites a pivot point near the bottom. The pivot point describes the point that the sprite uses to sort against other objects. If the character is in front (lower y) of this point, it will render on top of the bookshelf.

4. For your character, have its pivot point be near the feet. If your character is composed of multiple sprites, you may want a Sorting Group.

Extra reading about 2D Sorting: Unity - Manual: 2D Sorting

Hi there,
I have the same usecase of 2D Walls, and used the y pivot of the sprites for sorting.

Hovewer, the pivot also affects the offset of the tile on the tilemap. I cuerrntly can fix that by adjusting the offset for each tile in the tilemap pallet Grid Object. But this doesnt work for ruletiles. That is my problem.

I want to use ruletiles for walls, and when I change the pivot of the different sprites of the ruletile, it also offsets the tiles on the tilemap.

Is there a way where I can tell the tilemap to not use the sprite pivot for offsetting, only for y-sorting?
Any solution would be greatly appreciated!

Just have two tilemaps. One for the top of the wall and the side walls. The top walls should draw over the character no matter what, and side walls always draw behind the character. Easy.

Hi!
Thanks for you answer :smile:

That sadly wont work in my case. My caves are similar in perspective to stardew valley, where the walls consist of multiple tiles. And you can wall close to the walls so that the side of the character at some point just slips behind the wall.

I gladly found a way to achice this by modifing the unity tile and ruletile script, so that the pivot is no longer affecting the placement of tiles, only the sorting. Its rly convenient and fixes a lot of problems.

If anyone is interestet, I could share it.