Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Is it possibly to sort sprites along tilemap with top down sorting order?

Discussion in '2D' started by eses, Dec 18, 2018.

  1. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Think top down view with front facing side visible, in style of JRPG games

    So sprites can be sorted in this manner, using their pivot, sorting order or custom transparent sorting axis.

    Tilemap Renderer can be set to sort top to bottom, or however you want to view it, this makes it possible to have tiles higher in Y sort behind those lower in Y-axis.

    However, Sprites and Tilemap don't seem to be communicating between each other...

    I could change Sprite Sorting layer or Order in Layer, either for Sprite or for Tilemap, but it won't allow Sprite to go in-between tiles. If each row of Tilemap somehow had different order in layer, this would be easy.

    Any solution to this, other than start splitting tiles into go-behind and normal layers?

    Edit:
    I drew a picture. Something like this happens. Either sprites are in front of behind tiles fully. Sprites and tiles bot sort between themselves correctly, but there is disconnect between both. Dots are pivots, but this doesn't seem to matter.

     
    Last edited: Dec 18, 2018
  2. RidgeWare

    RidgeWare

    Joined:
    Apr 12, 2018
    Posts:
    67
    I literally made the same post in this thread yesterday:

    https://forum.unity.com/threads/til...-sorting-order-or-z-axis.532286/#post-4007938

    It's a limitation of the Tilemap system unfortunately. It seems the only way around it is to have 2 tilemaps for foreground tiles and background tiles. (Or create individual sprites/game objects for every single foreground tile, which can then be sorted with other sprites the usual way).

    I did read in another thread somewhere that the Unity 2D team are looking into this long term.
     
    eses likes this.
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @RidgeWare

    I haven't found your thread... so I'll read it. Anyway, if this is limitation and not user error, that's pretty big oversight, as Tilemap is rarely used alone without interacting objects. Then it is just more manual work.
     
    Last edited: Dec 18, 2018
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @RidgeWare

    Just to let you know, it might or might not be usable for you. After couple of ideas, I came up with one hacky solution:

    1. Set tilemap tile Orientation to custom.

    2. Rotate tile along x axis slightly (some fraction of degree, or one degree doesn't matter).

    3. Then assign z-buffer using shader, like Unlit/Texture to tilemap.

    This way sprites will go behind top parts of "up" extruding tiles, as long as their plane don't intersect with slanted tile.

    Edit:
    As you can see, tiles and sprites sort as intended... same goes for camera view, both ortho and perspective (of course with limitations) but anyone who is interested can test it. White sprite will sort with black sprite, and both sprites will be behind walls below, and in front of walls above.

     
    Last edited: Dec 18, 2018
  5. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
  6. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @jeffreyschoch

    thanks for the reply.

    Actually the gif is using transparency sort axis for sprites, like I mentioned.

    However, like I wrote, it doesn't seem to help with sorting sprites in-between tiles. AFAIK It will only help with sorting of sprites, not sprites vs tiles like the case is here.

    About the video; Is there some specific part that could help me? Not complaining but if there is some trick or obvious thing I've totally missed, I will check that part only.
     
  7. RidgeWare

    RidgeWare

    Joined:
    Apr 12, 2018
    Posts:
    67
    That's fine for sprites, but we're talking about tilemap tiles, where that process doesn't work properly.

    --
    @eses

    I've since played around with an addtional tile map for foreground walls, and to be honest I can live with it for the time being. It's more workload, but not a *huge* amount more. Also, I can make both wall tilemaps use the same layermask for raycasting purposes, so it makes little impact on the code.

    Hopefully in a new release they'll implement something for tilemaps that can sort with sprites both front & back.
     
  8. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    Last edited: Dec 19, 2018
    qttq23, eses and RidgeWare like this.
  9. RidgeWare

    RidgeWare

    Joined:
    Apr 12, 2018
    Posts:
    67
    Thanks, that's a great help. I could swear I tinkered with that option before, but obviously I hadn't used it properly.

    I'm not sure what the performance will be like compared to chunk rendering, but it's certainly a quicker design/workflow than buildng a foreground tilemap with chunk rendering.
     
  10. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @jeffreyschoch

    Hmmm... is this only available in 2018.3, I'm still in 2018.2 and only see Sort order, Culling bounds, Sorting layer and Mask interaction in Tilemap Renderer.
     
  11. RidgeWare

    RidgeWare

    Joined:
    Apr 12, 2018
    Posts:
    67
    It's quite possible. I only updated to 2018.3 a few days ago, and the option is sitting there right below Sort Order.

    It could prove to be a godsend. I've fully tested it now on my wall tiles (on 1 tilemap) and the sprites are now sorting correctly whether in front or behind a tile.
     
    eses likes this.
  12. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @RidgeWare

    Thanks for the info.

    Better late than never I guess. This kind of feature seems like a must for any game using tilemaps other than full side view or top down.

    I'll consider updating my Unity version.
     
    LiterallyJeff likes this.
  13. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    There's always the option of using regular sprite prefabs using a prefab brush or manually placing them as children of the grid. Using prefabs you can even have objects larger than one tile sorting properly based on root pivot.

    The benefits of batch rendering in a tilemap are great, but regular sprites will not tank your frames per second by any measure.