Search Unity

2.5D Overlap Problem Question

Discussion in 'General Graphics' started by bluevideogame, Jan 24, 2019.

  1. bluevideogame

    bluevideogame

    Joined:
    May 31, 2018
    Posts:
    10
    I have a problem where images change z drawing depending on the xposition of my camera - the image shows the problem - I want it so the positions of the images dont change drawing order to camera

    https://ibb.co/syHLY8d
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639
    I've seen that happen when using an alpha-transparent shader. Are you using something other than the regular sprite shader?
     
  3. bluevideogame

    bluevideogame

    Joined:
    May 31, 2018
    Posts:
    10
    Yes I am using a custom shader ~ do you know any way to fix?
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639
    Unless I'm out-of-date, Unity sorts alpha-transparent objects based on the distance between the object's transform pivot and the camera. This is an optimization for full alpha-transparent objects because having multiple transparent objects stacked can be pretty slow. If both of those tiles use the same shader, then this optimization is causing the problem that you're seeing (Although, I'd kind-of expect it would work differently in orthographic mode).

    Since you are doing pixel art, you probably don't really need full alpha transparency, so you could use alpha-cutout instead. Alpha cutout will not have this problem and will be more performant all-around.

    If you really need that alpha-transparency, then I think you can use something like Renderer.sortingOrder to manually control the order that your tiles are rendered, but I've not tried this myself.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Yeah, you'd have to set the render order manually to solve this, which means you have to set the sorting order for everything transparent in the scene. There's no easy way to enforce the order between two objects and not cause sorting issues with other things in the scene without taking complete control of the rendering order yourself.