Search Unity

z-index Concept...

Discussion in '2D' started by AhmadIssawi, Jun 24, 2018.

  1. AhmadIssawi

    AhmadIssawi

    Joined:
    Jun 4, 2016
    Posts:
    48
    hi every body ...
    when working in many other softwares and platforms ... the concept of the (z-index) was so clear and easy...
    when coming to my lovely Unity, i really worked many years and many projects, but this concept is still so ambiguous for me, and make for me each time problems....

    i believe that Unity Organizes this stuff very well, using a Wide collection of tools and factors (GO hierarchy in Unity, Z position, Layers ....), but i am really unable to collect the effect of all these tools in my mind at once, and understand the concept completely .. :(

    is there a reference (Pdf or web link or other) where we can Understand this concept Very easily and completely and quietly ??!

    Many thanks for any useful answer :)
     
  2. AhmadIssawi

    AhmadIssawi

    Joined:
    Jun 4, 2016
    Posts:
    48
  3. AhmadIssawi

    AhmadIssawi

    Joined:
    Jun 4, 2016
    Posts:
    48
    Please How can we Understand these 3 factors together, and then Use them to arrange correctly the big collection of Sprites and UImage and others ...
    1) Z position....
    2) Hierarchy in Unity...
    3) Layers and Sorting Layers...

    i am really got confused :(:eek:

    in more details (Photos) :
    PlayBoard and DashBoard are 2 Groups that contain a mixed of Sprites, UIimages and others...
    i want that EVERY GO in DashBoard is ABOVE Any GO in PlayBoard ...
    and also, some other issues inside each group....
    i tried to use the 3 factors mentioned above .... i did not arrived ...:(
     

    Attached Files:

  4. barskey

    barskey

    Joined:
    Nov 19, 2017
    Posts:
    207
    Z position (Z-coordinate of the Game Object Transform) is literally the z coordinate in 3D space. Even though the camera is 2D, anything closer to the camera in the z direction will appear in front of anything behind it. Z position can also be used to place objects in/outside of the camera view frustum. Note that you can always un-toggle the 2D button to see your 2D sprites, etc. in 3D at their actual z position.

    Hierarchy is used to parent game objects to others, which can be used for many purposes. Order in the hierarchy is specifically useful for scripting when you want to get a child object.
    https://docs.unity3d.com/Manual/Hierarchy.html

    Layers are used for the physics system, and can help decide which objects interact with other objects.

    Sorting Layers are used to categorize sprite rendering, and order in layer is used to further define which sprites render in front within a sorting layer.
    https://unity3d.com/learn/tutorials/topics/2d-game-creation/sorting-layers

    Hope this helps.
     
    nintendoking77 and AhmadIssawi like this.
  5. AhmadIssawi

    AhmadIssawi

    Joined:
    Jun 4, 2016
    Posts:
    48
    First : Thank you for your answer ....

    ok thank you ... i know this info .. so trivial ...


    But that means that the main Factor is the z-index .... regardless all other factors (Hierarchy - Sorting Layers ..)
    and also that all the GO are Subjects to the same rule.... i Hope that ... it will be so easy ....

    But what do you think about the attached Project ??
    the Z-pos are :
    Orange : -40
    next : 0
    green : 100
    blue : 50
    ??:(
    :mad:
     

    Attached Files:

  6. AhmadIssawi

    AhmadIssawi

    Joined:
    Jun 4, 2016
    Posts:
    48
    if the z-Poz is the only factor that control the look (which object is above the other) ...
    Why the Green is above the Blue ??
    Any answer Please ??
     
  7. AhmadIssawi

    AhmadIssawi

    Joined:
    Jun 4, 2016
    Posts:
    48
  8. barskey

    barskey

    Joined:
    Nov 19, 2017
    Posts:
    207
    I think my previous answer was incorrect. Z position does not affect rendering order. Only Sorting Layer, Order in Layer, and Sorting Groups.

    Likewise, Collider2Ds ignore Z position for determining collisions.
     
    AhmadIssawi likes this.
  9. AhmadIssawi

    AhmadIssawi

    Joined:
    Jun 4, 2016
    Posts:
    48
    Really ... very complicated subject !!