Super Tiled2Unity Sorting groups of layers

Hello everyone,

I am building a game with overhead-view so the “Custom Sort Axis” method of Super Tiled2Unity is very useful.
Now here is my problem.
I often use two or more layers with overlapping tiles that are supposed to be at the same hight (eg. a picture hanging on a pillar). I need these layers to be stacked (eg. the pillar must not be rendered in front of the picture). But I need the layers (as a package) to be sorted using a custom axis so that moving characters are rendered in front or behind of BOTH layers according to their position.

If the layers have the same “Sorting layer” and “Order in Layer” they both are - in relation to the characters - rendered correctly, but are often scrambled among themselves (eg. picture is behind the pillar).

Has anyone a solution to my problem or is there a possibility that an option to be able to stack layer groups will be added to Super Tiled2Unity? @Seanba
Thank You! :slight_smile:

Hi there, @Weaver. Sorting can be a real PITA in Unity and I thought ST2U handled this scenario through grouping but in putting something together for you I found a couple of bugs. I’ll put out an updated version of ST2U soon and and a GitHub repository that shows this kind of sorting (i.e. allowing you to stack decals unto a column while preserving sort order).

The gist of it is that you’ll be building a Tiled map “from the ground up”. I hope to have more for you soon.

In the time, what do you use for your Pixels Per Unit setting on tiles and sprites? Knowing that will be key to setting up the right custom sort axis.

2 Likes

Thanks for the answer @Seanba and for the amount of effort you’re pouring into this.
Currently I use 16 Pixels Per Unit on tiles and sprites.
I’m looking forward to the updated version. Thanks again.

So I’m guessing each tile in your map is 16 pixels wide and high?

(I’ll put my solution up this evening.)

Hi there, @Weaver. Check out this repo for an example. The README should explain how I got this effect but let me know if you need something explained better/further.

Keep in mind that for you, assuming your Tiled cells are 16 pixels high and given that your PPU is also 16 that you will want to use a z-value of -1 for your custom axis in your Unity Graphics settings.

tile-object-sorting

3 Likes

Wow, thanks so much!!
Yes, the tiles are 16 pixels high.
I’ll let you know if I run into any problems, but so far this seems to be exactly what I needed.

Hi again!

I ran into a problem when I tried to apply this method.
I think I managed to fix it, but not in a very elegant way…
Still this might help anybody encountering the same problem.

Basically this problem originated from me wanting my character to dynamically move between “height layers”, i.e. when moving up some stairs. Right now I accomplish this by changing the SortingLayer on the character sprite. So grouping together all height layers “above” and/or “under” the character, like in the example, made that really difficult.

My maps are buildt as follows. I have a base layer for every height and additional layers for decals, shadows etc. respectively, as they are needed.

I tried a lot of things. Best (and only working) solution so far was simply hardcoding SortingLayer, SortingOrder and z-value to every Layer in Tiled. SortingLayers corresponding to each height. The z-values only have to differ between layers using the same SortingLayer. In my case (with a z-custom-axis value of -1) the z-values of those layers had to have intervals of 1. So if I had 4 layers sharing one SortingLayer their z-values could be 0, 1, 2 and 3. The higher the values are the further the layers are rendered in front.

It’s a bit tedious hard coding all the stuff but so far it seems to work, meaning everything renders correctly while still being able to move your character between “height layers”. I’ll post an update if I run into any problems with that method.

EDIT: Ookay, sadly doesn’t actually seem to work as intended. The layers are sorted correctly, but the sorting of the character sprite is somewhat of a mess, so better disregard this post for the time being. Sorry.