Search Unity

Proper layering between GUIText and GUITexture objects

Discussion in 'Editor & General Support' started by StarManta, Jun 14, 2007.

  1. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I have an object composed of a GUITexture and a GUIText on top of it. There is one of these objects for each nearby character.

    Unfortunately, they don't layer correctly - although I can get GUITextures to layer themselves correcty (closer characters' labels showing up on top of farther ones), the GUITexts attached to these GUITextures seem to be immutably on top of all GUITextures.

    Has anyone else found a solution to this problem?
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Maybe the object is a child object of something thus the z order gets changed by the parent?
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I've tried that - the Text is a child of the texture, and whetever its local position is (positive or negative), it's always on top of the texture (and all other textures)
     
  4. shaun

    shaun

    Joined:
    Mar 23, 2007
    Posts:
    728
    Ive had some strange things happen when parenting GuiTextures and GuiTexts before.
    Generally, the way I solved the problem was to use int ZOrders for all guielements and also set the zorder for each object independently of its relationship with the parent. (i.e. a Parent GUITexture with Z=1 and the GUIText Z=2).

    I know this explanation might sound a bit simple, but ive found this technique to be very stable when using 3D objects to position 2D element zorders.

    Cheers
    Shaun
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I still haven't got a solution to this - properly ordering their Z positions doesn't work. Thought I'd bump it because it's become a pretty serious graphical problem.
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I figured it out. Turns out that GUI elements' Z Order is not affected by the parents - only their local Z Position. Is that a bug?
     
  7. FiveFingers

    FiveFingers

    Joined:
    Oct 15, 2009
    Posts:
    541
    We had this problem too!

    From the manual:

    I changed the Z transform of my guitexture/guitext
    to have them layered correctly.
     
  8. KAKE

    KAKE

    Joined:
    Apr 5, 2005
    Posts:
    57
    I feel like some sort of putz. How do I change the "local" z position vs the global one? I only see the one Z property in the transform panel. Is there a way to toggle between local and global for the panel that I'm not seeing?
     
  9. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    it will always show the local

    the global one is controlled by the root of the hierarchy which defines the 0,0,0 point for its childs, which do the same for their childs
     
  10. KAKE

    KAKE

    Joined:
    Apr 5, 2005
    Posts:
    57
    Never mind - lack of sleep has gotten to me. I was absent-mindedly adjusting the Z-scale rather than Z position. It works fine now.
     
    jtok4j likes this.
  11. heaversm

    heaversm

    Joined:
    Jul 12, 2011
    Posts:
    11
    I don't see a z-position for the guitexture or text, just a z-position for the game object itself to which the guitext is attached, and if I change this the text won't display in the proper position. Isn't there a stacking order unrelated to the object's actual position within the world?
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Right, that's what the z position is.

    Yes it will. The z position doesn't have any effect on a GUIText/Texture's location on the screen, it's used only for layering order.

    GUIText/Textures don't have a position in the world. The x/y positions are normalized viewport coords (not world units), and z is the layering order.

    --Eric
     
  13. Nick-Wiggill

    Nick-Wiggill

    Joined:
    Jan 31, 2010
    Posts:
    46
    While what Eric5h5 says is true, that doesn't answer your question, which is the same one I had:

    So if both the GUIText and the GUITexture are on the same GameObject (and thus have the same Z), and you want them to appear in a specific order, you have to add the components to the GameObject in the order you want them displayed (from top to bottom in the inspector).

    Example: I have a panel GameObject, and it contains both the panel background (GUITexture) and the panel text (GUIText). I obviously need the text to appear in front of the panel. So I add the GUIText first (higher in the inspector) and the GUITexture last (lower down in the inspector).
     
    Last edited: Mar 26, 2012
  14. NeoTeo

    NeoTeo

    Joined:
    Nov 1, 2012
    Posts:
    1
    This helped me.
    Thanks.

    :)
     
  15. ProbePLayer

    ProbePLayer

    Joined:
    Oct 19, 2012
    Posts:
    19
    This thread helped me as well. Thanks
     
  16. jtok4j

    jtok4j

    Joined:
    Dec 6, 2013
    Posts:
    322
    Oh Oh OH WOW! I am pretty *(W@JFSD at myself now. For months, I've avoided GUITextures and GUItext, due to the fact that I couldn't get the "z" values to actually work, and ALL THIS TIME, I've been trying to change the "Scale" Z's instead of the Position Z's... Oh wow, this is really dumb, (of me), but so helpful here on this post! Thank-you!