- Home /
Unity 5.0.1, GUI text always displays behind game objects
Just updated to the newest version on Unity. I've just started working on a 2D project. I've been trying to add some GUI text but it always displays behind the game objects. After adding the new GUI text and it creates the canvas component, I was under the impression that the canvas component was supposed to fit to the size of the screen, but instead it does this: http://puu.sh/hgfuv/f9008cb028.png The canvas is massive and so is the GUI text compared to the camera. I selected the 'Screen Space - Camera' for the render mode, which fits the canvas to the camera and makes the GUI text about the right size, the only problem is that the GUI text always appears behind game objects, like this: http://puu.sh/hgfKo/7e5f9877f6.jpg I really hope this isn't a bug and it's just me not understanding the new Unity GUI system very well. Any solutions?
Same problem here, it's highly annoying to keep zoo$$anonymous$$g in and out if you switch between scenes. Setting the canvas to a normal size renders it behind gameobjects, even if you set the Z value closer to the camera. So apparently the canvas has to be HUGE which is confusing when you like to work with exact pixel values - something you always do in a 2D game.
It's all very inconvenient and clumsy, you really start to wonder what the Unity devs were thinking when they implemented this system.
We can only hope that Unity 6 will fix all the 2D issues, the list goes on and on.
Answer by YoungDeveloper · Apr 16, 2015 at 09:21 PM
For always on top drawing use Screen space - overlay, and yes, it's huge and you should not worry about it. This is the closest alternative to old OnGUI() and will be drawn always on top.
If you want the elements to have depth - draw in layers, behind gameobjects or whatever use "Screen space - camera". If you select it Render Camera field will appear, which you must assign with your main camera. You will see that it also auto scales just like Screen space - overlay and rotates correctly with camera.
World space is in free world space, just like any scene gameobject.
Alright, is there anyway to shrink the size of the GUI text? It's massive and decreasing the font size just creates weird, blurry, almost unreadable text.
If you want small text to be extremely readable, i found one way that works. For Text component, set the scale to (for example) (0.3 0.3 0.3) and increase font size. Here's a setup i tried in seconds.
But if you select 'screen space - camera' the GUI appears BEHIND all game objects. Regardless of Z settings.
Answer by prateekpy-21 · Jul 23, 2015 at 12:21 AM
If u really want to add guitext do it by adding UItext just follow these steps: 1. In Hierarchy Creat-> UI-> Text. 2. Now set anchor texts others as per your requirement. 3. In script if u want to access it (C#) code then use using UnityEngine.UI; 4. Then create public GameObject guitext. 5. In inspector left click on the UIText->Canvas and select the child Text field and drop on inspector gameobject variable guitext. 6. Now in script access the text as: guitext.GetComponent().text 7. NOTE : Remember to add using UnityEngine.UI else error will occur. Also when moving object from hierarchy only Text should be moved else again error.
Answer by starrtennis · Feb 01, 2019 at 06:32 AM
Make the Sorting Layer of your Canvas in front of the Sorting Layer of your game objects.
Answer by Lord_Dov_Sabol · Sep 15, 2020 at 03:46 AM
I found a way that does not require any scripts (although i am not sure about what this will change or what the consequences are), if you go onto your canvas, and on the canvas component, change the "Plane Distance" from 100 to something like 10, it should be normal.
Hope this helps!
Your answer
Follow this Question
Related Questions
Canvas wired rotation bug 1 Answer
Canvas Text gets garbled 0 Answers
GUI co-ordinates bug? 1 Answer
GUI Problem 1 Answer
Use Unity UI For 2D Games Or Custom Objects Instead? 2 Answers