How to make UI>Text appear above sprites

I’ve been looking around as best I can, and I just can’t find a solution for this. I’m working on a 2D game, and I need a way to get UI Text objects to show up over sprites. I’ve read about hacky ways to get 3d text to show up over them, couldn’t even get those to work, however.

This would all be a lot easier if text objects had sorting layer options.

Thanks for your help.

Add a canvas component to the sprite object. On it mark “override sorting” and put the “Order in Layer” a smaller number than the canvas where the text is (usually -1 should do the trick if your layers are not changed)

@krazykhris875 Sorry for the 4 years late but this may help others with the same problem.

Text use the Sorting Layer from Canvas, and Canvas have the Default sorting layer by default. If you create new sorting layers for your sprites, they have a higher level that Canvas to print them in the scene. So you only need to move the Default sorting layer to a higher level than the sprites you want to cover with the text. Or, if you use the Default sorting layer for more objects in your scene, you can create a new top higher sorting layer and asign it to the Canvas. If you don’t see Sorting Layer field in Canvas component, you need first to select Screen Space - Camera option for the Render Mode field.

@Mavina

Hi there. Thank you for your time in answering. I’m afraid I didn’t explain very well, the issue I’m having is not that I need the text to follow a gameObject, but that I haven’t been able to get text to draw above a sprite at all.

I need to be able to have a sprite (that’s a background), and draw the text over top of it, with a UI>text object. So far, however, this hasn’t been doable.

Ideally just move it’s gameObject to the front using the parents transform.

parentOfText.SetAsFirstSibling() or parentOfText.SetAsLastSibling().

Hello from the future. On your canvas object there is a property in the inspector called “Sort Order”. You can also access it programmatically with: canvas.sortingOrder where canvas is an instance of Canvas on this object. Set the value to higher than 0 and it will put it above the sprite default. Or you can do the opposite and set the sorting order on your sprites to all be -1. I prefer the former.