Proper layering between GUIText and GUITexture objects

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?

Maybe the object is a child object of something thus the z order gets changed by the parent?

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)

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

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.

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?

We had this problem too!

From the manual:

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

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?

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

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.

1 Like

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?

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

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).

This helped me.
Thanks.

:slight_smile:

This thread helped me as well. Thanks

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!