Prevent Unity 3D Text from Always Appearing on Top while Maintaining Rich-Text Support

The TextMesh component in Unity has an annoyance which causes the text that it displays be rendered always on top. This is useful if you want your GUI elements to always appear on top but if you want to have a 3D text attached to a 3D object, this creates the weirdest results!

There’s already an entry in Unity’s wiki page detailing how the issue can be worked around using a custom shader. This YouTube video shows the application of the mentioned method (it’s quite useful even though the guy is speaking Russian!). Also, if you are not sure how a texture can be built using a font, follow the steps described in this awesome blog post.

The issue with the above method is that it messes with the rich text support of TextMesh. Essentially, all text will be rendered with the specified color of the created material. I found a better custom shader in the Unity 3D forum! This solved my z-depth issues.