UPDATE!! EDITED
Alright, so apparently I was wrong about my solution. Assigning the material to the font did not work. It only made the cause of the bug even more random, which is why I thought it was solved. I spent the whole night till morning and finally got rid of all of it with this solution.
-
Make sure all fonts are initiated and set when the game starts. If you are changing the font in the text component with a script, make sure it is not initiated twice or in later game time, all fonts should be set the moment game starts. I have some of the gameObjects hidden and only enabled when player enables it, so I suspect my script collided with other scripts during Start() or Awake().
-
This surprised me the most. Make sure your text component (Horizontal Overflow set as Wrap) width fits nicely with your Chinese or Japanese font, without any awkward spacing before it jumps to the next row. The bug will pop out when text exceeds three rows if this is not done.
These are the conditions that would allow the bug to occur (in my case).
-
The font has to be of foreign language(Japanese font or Chinese font).
-
The text component’s horizontal overflow is set as wrap and exceeds three rows of text.
-
The font or text component is disabled when game begins and is only enabled during the game by player or text is updated on the text component by player.
If you are facing this problem you may also refer to these few links that has similar issues, it might help you if my solution does not work. The first link shows a screenshot of the exact issue I faced.
Anyone who understands the cause of this bug or has a better solution please do leave a reply.
I would love to know more.
Previous post (Incorrect method):
Hi all! Are you struggling with UI fonts missing or not showing up on your android devices??
I WAS. But after hours of trial and error, I finally found the culprit.
Here’s the simple fix if you changed the font during runtime.
public Material fontMaterial;
public Text text;
public Font[ ] newFonts;
void AvoidFontBug()
{
text.font = newFonts[0];
text.material = fontMaterial;
}
That’s it. Or if you did not change the font but still face this issue, just make sure you set a Material for your Text component. It worked for me.
FYI, I’m using Unity 5.0 and my android devices are the Lenovo P1 and the Redmi Note 4x, android version 6.0.1 and android version 7.0. The font(.otf) could display Traditional Chinese and Japanese letters + Unicode, and is set as a dynamic font. Both had the same issue, the text just suddenly disappeared or becomes a distorted version of another font when new text components were initialized or text were updated by user input.