- Home /
CanvasRenderer text is behind sprites
In my 2D game, my UI text is rendering behind both UI and non-UI graphics. I cannot change the sorting layer because "CanvasRenderer" dose not have a sortinglayer option. What do I do?
edit: some clarification - I can change Z position and hierarchy order til I'm blue in the face, but anything above default sorting layer will render in front of the text. The text is behaving like a sprite that is on the default layer.
Answer by brlan10 · Dec 15, 2016 at 02:25 AM
I was using a "text" component, but I see that there are other text components available that don't use the very frustrating CanvasRenderer. I'm going to switch to using a Text Mesh.
Glad you found a solution, however I'd advise against using Text$$anonymous$$esh. It's notorious for having very bad performance.
Ins$$anonymous$$d, I'd recommend watching the official tutorials for the newest UI system. Once you figure out how it all works, it's incredibly powerful and can do a lot of really cool things.
https://unity3d.com/learn/tutorials/topics/user-interface-ui
Answer by seth_slax · Dec 15, 2016 at 01:52 AM
Non world-space UI elements are drawn in order of hierarchy, so anything lower in the hierarchy will be rendered on top. World space renders things based on Z positions.
For the sorting layer, in a standard canvas GameObject (GameObject>UI>Canvas), in the Canvas component, if set to World Space you can specify a layer.
Also, if you're using a Screen Space - Camera canvas, lessen the Plane Distance so it's closer to the camera, then it should render it over any non-UI graphics.
I can change Z position and hierarchy order til I'm blue in the face, but anything above default sorting layer will render in front of the text. The text is behaving like a sprite that is on the default layer.
$$anonymous$$y layers are set up like [background > default > midground]
The text is rendering above background, and below midground. Very strange to me that it would behave on a sorting layer when you cannot modify its sortinglayer.
Are you using the Canvas object (GameObject>UI>Canvas), or just an object with a CanvasRenderer component? You'll have much better results if your UI elements are children of a proper Canvas object.
Answer by coolamigo · Jul 19, 2021 at 06:12 AM
Keeping the parent an empty object worked for me some how
Your answer
Follow this Question
Related Questions
UI - clamp the movement of a panel 0 Answers
Difficulties with world space canvas interaction 1 Answer
Instantiated UI objects with image components not appearing, rest of object works fine. 0 Answers
Getting the overlapping pixels between a UI mask and a UI image 0 Answers
UI button are sliced after exporting 0 Answers