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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Renderer.sortingOrder maxes out around 32000?

Discussion in '2D' started by TinyMobGraham, Nov 21, 2013.

  1. TinyMobGraham

    TinyMobGraham

    Joined:
    Oct 17, 2013
    Posts:
    38
    I have a custom isometric tilemap system created with 2D Unity. It uses the renderer.sortingOrder to ensure building sprites are drawn ontop of each other correctly depending on their tilemap position. This is very important to ensure the perspective looks correct. In general this works well.

    However, it seems that if you set the renderer.sortingOrder to 32768 or greater then it changes it to a negative value and the sprite disappears from view. The Unity documentation says this value is an int but I guess it has a really low upper limit? How can I work around this? Why is the limit so low?
     
    Last edited: Nov 21, 2013
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Sounds a bit overkill - you could sort them without this by using CameraSortMode and offsetting the mesh origin point instead which gives you unlimited variation (although it's a hack as well).

    Why not use the minus range as well, or is there a problem with this?

    I'd imagine the reason it's that number is because its a signed short int (65536). I guess an int might be possible, see what Unity has to say about it.
     
  3. TinyMobGraham

    TinyMobGraham

    Joined:
    Oct 17, 2013
    Posts:
    38
    I tried using the negative values too, but I can't get any negative sortingOrder sprite to be rendered. Perhaps I am doing something wrong but that is what I've found so far. I will investigate offsetting the mesh z order and putting the camera really far back. This seems hacky but it might be my only option if I want a tilemap that has any real size. Thanks
     
  4. JASON01

    JASON01

    Joined:
    Apr 30, 2014
    Posts:
    4
    Just ran into the same issue... at the very least this should be documented
     
    TruffelsAndOranges likes this.
  5. keely

    keely

    Joined:
    Sep 9, 2010
    Posts:
    967
    It is indeed internally signed 16-bit value. As of writing this the negative values also work. Not sure if that was the case in 2013 when this thread started. The bottom line is that sortingOrder was not designed to solve cases like 64k+ objects.

    I will make sure that this gets documented.

    The best workaround is what hippocoder suggest: The combination of CameraSortMode, z-value and depth buffer.