Search Unity

Drawing order of Meshes and Sprites

Discussion in '2D' started by Lexandritte, Nov 19, 2013.

  1. juaa

    juaa

    Joined:
    Feb 4, 2016
    Posts:
    4
    hafizmrozlan likes this.
  2. stuepfnick

    stuepfnick

    Joined:
    Apr 19, 2017
    Posts:
    9
    Thanks everyone. In the end I had to use a 2nd camera anyway. It's quite easy, if you know how. Just set the layers you want to render on each camera. That was everything for main camera and UI for OverlayCam. And made the Overlaycam as child.

    Also in Awake () I did set every single setting from Main Camera to the overlay-camera, like isOrthographic, size, field of view, near/far Clipping plane and so on … (so it also works, if you forget to that everything the same in both cameras)

    @GiyomuGames: Changing the rendering queue did not help at all. Anyway it was default 2000 for the tent and 3000 for the sprite, I tried to set it up to the maximum of 5000, but did not help.
    The sprite renderer would need to ignore the depth buffer, which only seems to be possible with a second camera. So the initial suggestion was the best anyway, just needed to figure out, how it works.

    @juaa: Thanks for that tip, will have a look at this. Strangely i.e. the TestMeshRenderer uses the sortingOrder and sortingLayers, but you cannot set it in the inspector. So for the moment I just opened the Prefab in a Text-Editor and changed the value there (which works fine, as prefabs are only regular text files).
    But being able to set the values in the inspector (as it should be possible by Unity as Default) is for sure a better way. Of course you can also set the sorting Stuff in code in Start(), Awake() or similar methods (wherever it is needed)

    Btw. it was a mistake, that you can set:
    overlaycam.transform.position = maincam.transform.position; and
    overlaycam.transform.rotation = maincam.transform.rotation;

    That way you cannot set both to the same reference,
    because the Vector3(position) and Quaternion(rotation) are structs, so there cannot be a second reference to the same object, as they are not objects, just value types.

    it would need to be:
    overlaycam.transform = maincam.transform;

    Only then they would be linked together (2 references to same object), because Transform is a class and so both transforms would reference to the same object and both would have the same values all the time then.

    Thank you all for the help!
     
  3. agiro

    agiro

    Joined:
    Jan 3, 2016
    Posts:
    193
    Thank you, You and Neror are legends. I thought I'll never get around this :D
    By the way, how should one start learning to code editor extensions? It seems way too valuable not to know.
     
  4. KennethOAguilar

    KennethOAguilar

    Joined:
    Feb 25, 2015
    Posts:
    6
    Amazing! This worked perfect. Thank you!
     
  5. Kishore0525

    Kishore0525

    Joined:
    Dec 12, 2018
    Posts:
    3
    how to set the order for quads as sorting layer


    https://answers.unity.com/questions/1064940/unity-5-meshrenderer-and-sortinglayer-not-working.html


    public string sortingLayerName = string.Empty; //initialization before the methods
    public int orderInLayer = 0;
    public Renderer MyRenderer;



    Now add this below Method


    void SetSortingLayer()
    {
    if (sortingLayerName != string.Empty)
    {
    MyRenderer.sortingLayerName = sortingLayerName;
    MyRenderer.sortingOrder = orderInLayer;
    }
    }


    Call this above method in start() method

    This Works:):):)