Search Unity

Tile Map: How to change one tile's sorting order or z-axis?

Discussion in '2D' started by twinmatrix, May 20, 2018.

  1. twinmatrix

    twinmatrix

    Joined:
    Sep 6, 2012
    Posts:
    38
    I need individual tiles on certain tile maps to calculate their sorting order or z-axis relative to objects around it.

    For example, I have a ROAD SIGN. The player can walk behind it like this:

    [PLAYER]
    [SIGN]

    Now the sign is in front of the player.

    Or the player can stand in front of it like this:

    [SIGN]
    [PLAYER]

    Now the player is in front of the SAME tile.

    How can I achieve this?

    And it gets more complicated when I consider that other GameObjects (for example, animals or random human characters) also need to be able to move in front and behind one tile.

    RPG Maker has this standard but I don't know how to achieve it in Unity...
     
  2. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
  3. twinmatrix

    twinmatrix

    Joined:
    Sep 6, 2012
    Posts:
    38
    No, you misunderstand the question.

    I need the layers of an individual tile to change dynamically. Not an entire tilemap.
     
  4. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    A Tilemap in Unity is like a Layer in Tiled.
    You can change the layer of an individual tile by moving it from one layer to another.
    If you have a Back layer and Fore layer you can put grass etc on Back and signs etc on Fore.
    At least that is how i did it... maybe a better way good luck :)
     
  5. twinmatrix

    twinmatrix

    Joined:
    Sep 6, 2012
    Posts:
    38
    If I need each barrel and chest to have their sorting order changed dynamically I will need to make 500+ tilemaps for one scene hehe
     
  6. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    idk, you can paint normal prefabs and objects into tilemap too
     
  7. nholdDET

    nholdDET

    Joined:
    Apr 17, 2018
    Posts:
    7
    You used to be able to change the rendering type to individual, I.e each tile was a single mesh and you could change sorting order from z to y in project settings. However this option seems to no longer be available. I would like to know the expected workflow to get this sorted as well:

    https://forum.unity.com/threads/render-mode-chunk-vs-individual-any-more-info.444775/

    Generally you use tiles because it's more performant than GameObjects in the case of rendering a tile, I am sure we have all written our custom brushes.
     
  8. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    could anyone provide a more concrete example though?
    why would it not be enough to put a sign or a barrel or a chest on a foreground layer?
    it what actual situation would each barrel need it's own layer?
     
  9. nholdDET

    nholdDET

    Joined:
    Apr 17, 2018
    Posts:
    7
    No-one is saying or even wants to put each barrel on their own layer, it's about painting certain tile objects and rendering them based on their y value. This allows your character to dynamically change their order based on y and walk up to say, fences, barrels or trees from the top and bottom and render in the correct order. Hell you could chunk purely on the x axis and render them on the y and it would work out the same.
     
    VOTRUBEC likes this.
  10. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
  11. nholdDET

    nholdDET

    Joined:
    Apr 17, 2018
    Posts:
    7
    I'm interested in seeing your workflow rather than just the end result.
     
  12. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
     
  13. nholdDET

    nholdDET

    Joined:
    Apr 17, 2018
    Posts:
    7
    Yeah, a very slow workflow. It becomes tedious without a lot of brush scripting(To auto add parts of tiles to specific layers).
     
  14. RidgeWare

    RidgeWare

    Joined:
    Apr 12, 2018
    Posts:
    67
    Is there any consensus for getting around this major limitation of tilemaps in Unity? I'm currently making a game with large dungeons with a vertical depth effect, so I have endless foreground walls and background walls to manage.

    Would the best option be to simply have an extra tilemap for foreground walls? I already have 2 separate tilemaps for walls/ground, so one more tilemap for south-facing walls wouldn't be much more work. They nicely overlap so drawing the tiles would be easy.

    I think I prefer that to creating hundreds and hundreds of individual objects for every tile in the foreground walls.

    Such a shame this major problem was overlooked when it was implemented.
     
  15. khanstruct

    khanstruct

    Joined:
    Feb 11, 2011
    Posts:
    2,869
    My plan is to position the sprites in a way that these taller ones are 2 tiles high. Then you put the normal collision on the bottom half and put the top half on the foreground. Just be sure the height of your character vs. the position of the collider prevents their head from reaching the top half when standing in front of it.
     
  16. RidgeWare

    RidgeWare

    Joined:
    Apr 12, 2018
    Posts:
    67
    Just to confirm, Unity 2018.3 solved this issue for me completely with the new Render Mode setting in the TileMap Renderer. By rendering tiles individually, they now sort correctly with every sprite that moves in front or behind.

    So there's no more need for 2 separate tilemaps for foreground and background wall tiles.
     
  17. khanstruct

    khanstruct

    Joined:
    Feb 11, 2011
    Posts:
    2,869
    I must be doing something wrong. I've messed with every setting I can find, but my player is always appearing in front of my tiles. Is there some tutorial or helpful article (the Unity docs aren't much help)?
     
  18. RidgeWare

    RidgeWare

    Joined:
    Apr 12, 2018
    Posts:
    67
    I suggest perhaps posting some screenshots of your inspector windows for both your sprite and the tilemap.
     
  19. LakeIshikawa

    LakeIshikawa

    Joined:
    Dec 14, 2013
    Posts:
    5
  20. binghamd

    binghamd

    Joined:
    Nov 15, 2017
    Posts:
    2
    easier solution is to adjust the sorting axis:
     
  21. Daniel_Abeleira

    Daniel_Abeleira

    Joined:
    Oct 16, 2018
    Posts:
    7
    That last response isn't helpful at all with tilemaps and it's very performance heavy. What the original question was is how to get the y-axis sorting to work on individual tiles on the same tilemap, so that the player appears "behind" the tiles that are lower than him and "in front of" the tiles which are taller than him. Using a single tilemap and a single layer.
    To do this, just change the Render Mode in the (foreground) Tilemap component to Individual. Then in the Project Settings change the sorting to be based on a custom axis (the Y axis). This will make your objects calculate the Y position based on the individual tile's position.
    Might not work so well for isometric art though. Hope that helped.
     
    Last edited: Jul 29, 2020
    Wolfgangbr, Mercbaker, fspore and 6 others like this.
  22. WorkshopInProgress

    WorkshopInProgress

    Joined:
    Feb 21, 2019
    Posts:
    2
    Thank you! I just found this post and this fixed most of an issue I was facing! I have to remake a map as a result, but it'll save SO much time in the long run.
     
  23. Horse_Manly

    Horse_Manly

    Joined:
    Mar 14, 2014
    Posts:
    3
    When you're using a render pipeline, you lose the option to sort based on Y in the project settings. I'd like to use the render pipeline for 2D lighting. Does that mean I have to choose between lights and sorting properly?
     
    Kaldrin likes this.
  24. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
    Capture - Copy.PNG
    The 2D Renderer simply moves where you set the custom axis from Project Settings to the renderer asset itself. You're good to go.
     
    christh and Kaldrin like this.
  25. Kaldrin

    Kaldrin

    Joined:
    Jul 10, 2018
    Posts:
    46
    Hi! Thank you for your answer, this does help!
    However I cannot find the custom axis settings in my project, I am using the Universal Render Pipeline with Unity 2019.4.15, do you happen to know where I can change this setting?
     
  26. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,514
  27. Kaldrin

    Kaldrin

    Joined:
    Jul 10, 2018
    Posts:
    46
  28. GameRav3n

    GameRav3n

    Joined:
    Jun 4, 2018
    Posts:
    1
    Hello everyone my first post here I just wanted to thank Daniel Abe for the fix and to add that I was only able to get this to work if the player and Collision grid are on the same Layer so my Sorting Layer "Player" Order 0. If anyone has suggestions for this please let me know because I do see this being annoying as hell and causing more issues later.
     
    Kaldrin likes this.
  29. Kaldrin

    Kaldrin

    Joined:
    Jul 10, 2018
    Posts:
    46
    This is totally normal, this is the intended behaviour
     
  30. ZadiusC

    ZadiusC

    Joined:
    Apr 24, 2020
    Posts:
    3
    I have been looking for this answer for hours! Thank you!
     
  31. Jess_G

    Jess_G

    Joined:
    Aug 2, 2021
    Posts:
    1
    did you do this with sorting layer in the tilemap renderer component? it doesnt seem to work for me...
    (i'm trying to put ground tiles over wall tiles in a cave)
     
  32. Kaldrin

    Kaldrin

    Joined:
    Jul 10, 2018
    Posts:
    46
    It should work, that is strange