Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Have layer order a sprite over a meshrenderer.

Discussion in '2D' started by Zerequs, Mar 21, 2023.

  1. Zerequs

    Zerequs

    Joined:
    Mar 21, 2023
    Posts:
    4
    Hello, I have a 2d game, but I want to add 3d objects. I was wondering if there was a way to order the layers so as to have the player sprite appear on top of the 3d object in the order?
     
  2. flasker

    flasker

    Joined:
    Aug 5, 2022
    Posts:
    193
    transparency sort axis. sort by z, change z to sort
     
  3. Zerequs

    Zerequs

    Joined:
    Mar 21, 2023
    Posts:
    4
    Ok, I’m a little new at this. What’s a transparency sort axis and how would you sort by the z axis in a 2d game?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    Three (3) primary ways that Unity draws / stacks / sorts / layers / overlays stuff:

    https://forum.unity.com/threads/orthographic-camera-rendering-order.1114078/#post-7167037

    In short,

    1. The default 3D Renderers draw stuff according to Z depth - distance from camera.

    2. SpriteRenderers draw according to their Sorting Layer and Sorting Depth properties

    3. UI Canvas Renderers draw in linear transform sequence, like a stack of papers

    If you find that you need to mix and match items using these different ways of rendering, and have them appear in ways they are not initially designed for, you need to:

    - identify what you are using
    - search online for the combination of things you are doing and how to to achieve what you want.

    There may be more than one solution to try.

    Additional reading in the official docs:

    https://docs.unity3d.com/Manual/2DSorting.html

    And SortingGroups can also be extremely helpful in certain circumstances:

    https://docs.unity3d.com/Manual/class-SortingGroup.html
     
  5. Zerequs

    Zerequs

    Joined:
    Mar 21, 2023
    Posts:
    4
    So, it took some time, but from what o figured out, z depth is only used in 3d games not 2d games.

    Sprite renderers only work on sprites and not mesh or 3d objects.

    And canvas’ are used to create UI. So… I don’t think that works with 3d objects.

    I read the docs and the gist is that I need a way for the player controller to recognize the meshrenderer. How would I do that?
     
  6. flasker

    flasker

    Joined:
    Aug 5, 2022
    Posts:
    193
    all you need to do is make sure that all objects are in the correct z position

    the transparency sorting axis can be found in your renderer if you are using URP or on your settings if not. You can just google for transparecy sort axis to find the location and then set it ot z=1 or z=-1, depends what you want
     
  7. Zerequs

    Zerequs

    Joined:
    Mar 21, 2023
    Posts:
    4
    That still didn’t seem to work.
     
  8. flasker

    flasker

    Joined:
    Aug 5, 2022
    Posts:
    193
    thats life