1

I am trying to add TextMeshPro on a game object(sprite) outside the UI in 2D world. So I created a sprite to act as the background and parent game object then I put a canvas as the child of the sprite. Finally I put the TextMeshPro as the child of the canvas. I set the canvas render mode to world space. I am programmatically adding the sprite game object to the scene. The TextMeshPro on some portions of the screen does not show its text but when I move it around, the text shows on other portions of the screen.

Node GameObject

Above is the structure of game object, the node is the sprite.

enter image description here

This is the result of the TextMeshPro. Node 1,2 and 3 are showing the text but Node 4 and 5 are not. If I move Node 4 and 5 to the area where Node 1,2 and 3 are, it shows its text.

jps
  • 20,041
  • 15
  • 75
  • 79
Kenart
  • 285
  • 3
  • 14
  • Does something speak against having one single Canvas and rather make the `Node` and `Image` and spawn them all as child of the single Canvas? – derHugo Apr 25 '23 at 13:47

1 Answers1

2

Put the canvas and the sprite in the same sorting layer and give the canvas a bigger order, this will make the UI elements appear in front of the sprite.

Sorting layer order

If the canvas and the sprite have the same order, the display order is related to their distance from the camera.

shingo
  • 18,436
  • 5
  • 23
  • 42
  • Thanks, it did the trick. I added a new sorting layer, assigned the layer to both the node(sprite) and the canvas. I then increased the order of the node(2) and the canvas(4) ensuring the canvas has a higher order so that it can be drawn above the node. It is a problem of the order layers, simply increasing the order of the two game objects using the default sorting layer works too but it's good practice to group the sorting layers. – Kenart Apr 25 '23 at 17:02