0
\$\begingroup\$

I want to create a UI for a VR game to use it as a loading screen, the scene has a camera an image, a text mesh and a loading icon, the image is the background and the text and loading icon should be on top of it.

The problem is that the text is under the image:

enter image description here

For the image I tried using a UI image and a 2D sprite renderer, both give the same result, I also have layer 5:UI, 6: subtitules and the 0:default but it does not matter what I choose for each GameObject it always stays this way.

Here are the settings for the image and the text:

enter image description here

enter image description here

Also as requested here is the hierarchy of the UI elements where Fondo is the background image, Carga is the loading icon, and Texto is the text mesh that is giving me trouble, the Logos object is an object that is shown just the first time you open the game, so when enteriong the scene Logos is active and Consejos is not. If it is not the first time we open the scene it is deactivated and Consejos activates:

enter image description here

Any ideas?

\$\endgroup\$
4
  • \$\begingroup\$ Please include another screenshot how you set up your hierarchy (mainly the canvas) \$\endgroup\$
    – Zibelas
    Commented Apr 16 at 6:58
  • \$\begingroup\$ Forgot that, thanks! \$\endgroup\$
    – Alejandro
    Commented Apr 16 at 10:18
  • 1
    \$\begingroup\$ Canvas is rendered from top to bottom. If the text should be on top of other elements, it needs to be further down in that list \$\endgroup\$
    – Zibelas
    Commented Apr 16 at 10:26
  • \$\begingroup\$ @Zibelas You should have posted that as an answer. that way I wouldn't have just beat you to it. :) \$\endgroup\$
    – Philipp
    Commented Apr 16 at 10:39

1 Answer 1

0
\$\begingroup\$

As you can read in the documentation:

Draw order of elements

UI elements in the Canvas are drawn in the same order they appear in the Hierarchy. The first child is drawn first, the second child next, and so on. If two UI elements overlap, the later one will appear on top of the earlier one.

To change which element appear on top of other elements, simply reorder the elements in the Hierarchy by dragging them. The order can also be controlled from scripting by using these methods on the Transform component : SetAsFirstSibling, SetAsLastSibling, and SetSiblingIndex.

Another thing you can do to control the render order of UI objects is to put them on different canvases. Which is often a good idea for performance reasons anyway (A change on one element of a canvas means that the whole canvas needs to be redrawn, but other canvases do not). You can then control the draw order of the different canvases by changing the "Sorting Layer" and "Order in Layer" in the inspectors of the canvases.

The "Layer" drop-down in the upper-right corner of the inspector of every game object isn't for controlling render order... usually. It can be when you have a setup with multiple cameras with multiple culling masks. But that requires a much more complex setup. The actual function of that dropdown is to control which camera renders what and what collides with what.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ There's another subtle problem here you might want to add to your answer: they're using a TextMeshPro component with a MeshRenderer, instead of the TextMeshProUGUI component with a CanvasRenderer. The canvas rendering order will only apply to the UI version. \$\endgroup\$
    – DMGregory
    Commented Apr 16 at 13:08
  • \$\begingroup\$ Thank you all. I did a mix of everything, I created different canvas for the static objects and the changing ones, I change the hierarchy and used dorting layers both worked. \$\endgroup\$
    – Alejandro
    Commented Apr 17 at 6:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .