Proper layering between GUIText and GUITexture objects

Discussion in 'Unity Support' started by StarManta, Jun 14, 2007.

  1. StarManta

    StarManta

    Member

    Joined:
    Oct 23, 2006
    Messages:
    3,011
    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
    Messages:
    3,526
    Maybe the object is a child object of something thus the z order gets changed by the parent?
  3. StarManta

    StarManta

    Member

    Joined:
    Oct 23, 2006
    Messages:
    3,011
    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

    Member

    Joined:
    Mar 23, 2007
    Messages:
    719
    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

    Member

    Joined:
    Oct 23, 2006
    Messages:
    3,011
    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

    Member

    Joined:
    Oct 23, 2006
    Messages:
    3,011
    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

    Member

    Joined:
    Oct 15, 2009
    Messages:
    472
    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

    Member

    Joined:
    Apr 5, 2005
    Messages:
    49
    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

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    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

    Member

    Joined:
    Apr 5, 2005
    Messages:
    49
    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.
  11. heaversm

    heaversm

    New Member

    Joined:
    Jul 12, 2011
    Messages:
    4
    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
    Messages:
    25,565
    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

    New Member

    Joined:
    Jan 31, 2010
    Messages:
    45
    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

    New Member

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

    :)
  15. ProbePLayer

    ProbePLayer

    Member

    Joined:
    Oct 19, 2012
    Messages:
    7
    This thread helped me as well. Thanks