Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Tilemap individual render mode help

Discussion in '2D Experimental Preview' started by SorneBachse, Dec 10, 2019.

Thread Status:
Not open for further replies.
  1. SorneBachse

    SorneBachse

    Joined:
    Dec 27, 2012
    Posts:
    62
    Hey all.

    I'm having trouble finding any useful information/tutorials about the tilemaprenderer order settings (chunk and individual).

    I can't seem to get this sort of behaviour working for my project:
    I found that from this reddit post: https://www.reddit.com/r/Unity3D/co...to_change_one_tiles_sorting_order_or/e8k77as/

    What they got going is the wall tile sorting, where the player can navigate on both sides of the wall and it being sorted properly.

    But what they are doing there is apparently instantiating new game objects when the game starts. This seems like a hack, and you lose a lot of the performance benefits from the tilemap.

    Is there currently no way to achieve this, other than place individual game objects? Are there no examples or anything on how to use the render mode?

    Thanks in advance.
     
    Last edited: Dec 10, 2019
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    To accomplish this with the TilemapRenderer2D and be able to sort individual Tiles on the Tilemap with other SpriteRenderers, you will need to make use of the Individual Mode of the TilemapRenderer2D and the camera's Custom Sorting Axis. This will allow you to sort the Renderers based on the screen position of your Renderers where the higher you are on screen, the further back you are and therefore will be drawn before other Renderers.

    Some details can be found here: https://docs.unity3d.com/Manual/Tilemap-Isometric-CreateIso.html and a small example at https://github.com/Unity-Technologies/2d-techdemos (under IsometricZAsY).
     
  3. SorneBachse

    SorneBachse

    Joined:
    Dec 27, 2012
    Posts:
    62
    Hey, thanks for the reply.

    It seems that the custom sorting axis option is not there when using the 2DRenderer inside the URP (LWRP). Is the feature missing or moved to somewhere else?
     
  4. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    1,068
    It is currently hidden when URP is set, which should be updated in a future URP release.

    To set it, you will temporarily need to remove the URP asset to switch to Built-in RP, set the custom axis option and set back your URP asset. Alternatively, you can set the custom axis option on your Camera component itself using scripts.
     
  5. SorneBachse

    SorneBachse

    Joined:
    Dec 27, 2012
    Posts:
    62
    Alright, that seems very unintuitive like many other things I've encountered with the URP.
    We've decided to switch back to the legacy render pipeline for now, until things are more fleshed out.

    Thanks for the help though!
     
  6. treecki

    treecki

    Joined:
    Feb 6, 2017
    Posts:
    29
    For those using URP in 2021. Setting the individual sorting order is not available in the normal inspector settings, but if you switch to Debug settings, you can switch from Chunk to Individual.

    My only question now, is can I set the sorting order of those individual tiles in code and how? Like can I set a tiles sorting order higher for a ceiling or low for a floor?
     
  7. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    The TilemapRenderer lets you set Chunk or Individual Mode. It also lets you see Sorting Layer and Order in Layer for all tiles within that tilemap. https://docs.unity3d.com/Manual/class-TilemapRenderer.html In 2021, the TilemapRender shouldn't require going into Debug mode.

    There's no way to set sorting orders for individual tiles. Typically people have several tilemaps, for example one for floor and another for walls, each with a different sorting order, and with the floor being Chunk Mode and walls being Indiivdual Mode. This ensures floor is rendered below the walls. And the wall's Individual Mode allows it to sort vs. character in front/behind.The floor's Chunk Mode renders it efficiently but it then loses its ability to sort properly against a character.

    To set by code, you can use the tilemapRenderer scripting API
    https://docs.unity3d.com/ScriptReference/Tilemaps.TilemapRenderer.html

    Special cases - like an individual object that for some reason needs to change its sorting order - might best be handled by gameobjects with SpiteRenderers.
     
  8. Saulius

    Saulius

    Joined:
    Aug 10, 2010
    Posts:
    21
    I got that working, but there is a problem with objects that are bigger than 1 tile. Is there any way to fix this? Maybe I doing something wrong or this is just not possible with current system?
     

    Attached Files:

  9. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,513
    It's two sprites, so there are two pivot points. Make it one sprite with one pivot point nearer to the bottom.
     
  10. Saulius

    Saulius

    Joined:
    Aug 10, 2010
    Posts:
    21
    Big thanks now it works just fine. I didn't think you can do such thing with tilemap.
     

    Attached Files:

  11. zakhep82

    zakhep82

    Joined:
    May 12, 2018
    Posts:
    1
    I am sorry, but could you please tell, how exactly have you done this? I am struggling with this exact part of the problem.
     
Thread Status:
Not open for further replies.