I have been playing with 3D Text (via GameObject/Create Other/3D Text) because from what I read in the documentation this could be used within a scene to display text. My issue is that when i attach this text to an object and move the object behind other objects the text is still visible.
My test scene is rather simple and consists of a sphere and a 3D Text object, I move the 3D text object back and forth along the Z axis, but this only has the effect of making the text smaller but still visible even though it is behind the sphere.
The reason I would like to do this is so that I can have a âlabelâ hover above an object as the object moves around the scene, and if the object were to move behind another object (i.e. a building) the text would also move behind the building and not be visible.
Does anyone know how to get the text to be part of the 3D scene so that it is occluded by objects which appear in front of the text?
3D Text is rendered on top of everything else, yes. I donât know if thereâs a way to partially occlude it, but you can raycast or linecast to the camera and if anything is blocking, it doesnât display.
If the TextMesh can be used for road signs, to me, that indicates that it is occluded by other parts of the world, i.e. a road sign behind a truck/building/hill/etc.
It is true however that 2D GUIText is drawn in front of everything else.
Please correct me if I am wrong and have misunderstood what the documentation for TextMeshes is saying.
This is because the âZTestâ value in the built-in Text shader is set to âAlwaysâ. Create a copy of the Text shader in your assets directory, and set the ZTest to LEqual and it should work fine.
Iâm not entirely sure why ZTest is set to Always for the 3D text shader, actually I agree that the 3D text (being in 3D space) should be occluded by objects in front of it. Perhaps it is because this same shader is used for both 2D GUI text and 3D text?
is this just supposed to work once you have a copy of the font.shader in your assets folder? I have followed these instructions but it doesnât seem to make any difference to any 3d text I have in my scene.
Is there a way to apply the shader to 3d text as a component?
I just encountered this problem myself, and found this thread. Thank you so much, also for summarizing the steps at the end! This was really very helpful.
Hello, I have the same problem and the described fix seems to work - almost:
As soon as I attach the new material to the TextMesh it is shown behind the other objects as expected, unfortunately itâs also not readable anymore. Just big white blocks⌠What am I doing wrong?
Hello andeeee, thanks for the response.
I created a prefab and added a default â3D Textâ.
I instantiate it with a script: Instantiate(Resources.Load("MyText"));
If I change the font or the renderer material of the prefab the text becomes unreadable, just the default settings work.
When you change the Material (the font texture) used by the TextMesh make sure to change the Font (same place you set the string to display) used in the TextMesh aswell. if they are not thesame the text will be unreadable.
Assign shader to the material (âZTest LEqualâ)
Create custom font (assets->create->custom Font)
Assign the new material to the new font
Assign the new font to text mesh
Assign the new material to text mesh renderer
This is what happens:
After step 5 there is readable text, but it shows a part of the font alphabet, not the text it should show.
After step 6 this text is not readable anymore, just white blocks.
OK, got it working now. In case others run into the same problem: I had to copy an existing font into the asset directory first. The font will show-up as node with its material and the shader as children. (Somehow this failed when I tried it earlier - or I just failed to see the children)
From then on itâs pretty straight forward:
Assign shader to the font material (âZTest LEqualâ)
In the past I have had a modified text shader attached to my font material, as described above. When I upgraded to 2.6, evidently the fonts were re-imported and now use the standard text shader. The shader is grayed out and I canât find a way to change it back to my modified shader.
Does anyone else have this problem or know what to do (or try)?.