Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

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:
    30
    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:
    30
    No, you misunderstand the question.

    I need the layers of an individual tile to change dynamically. Not an entire tilemap.
     
    ZombByeGod and Egg like this.
  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:
    30
    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:
    5
    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:
    5
    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.
     
  10. rakkarage

    rakkarage

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

    nholdDET

    Joined:
    Apr 17, 2018
    Posts:
    5
    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:
    5
    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:
    65
    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,865
    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:
    65
    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.
     
    ShervinM, GuiTeK and khanstruct like this.
  17. khanstruct

    khanstruct

    Joined:
    Feb 11, 2011
    Posts:
    2,865
    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:
    65
    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:
     
    0skuro, cnkeats and rakkarage like this.
unityunity