Why are my Unity UI fonts rendering incorrectly?

I am having a problem with the Unity UI Text component on iOS where the text will be missing seemingly random letters, or the characters will just disappear entirely. I can’t seem to reproduce the issue in editor.

Here are some screenshots:

40687-text4.png

40686-text3.png

The text on this button is supposed to say “Collect”. Sometimes letters are missing (not always the same letters), and other times none of the letters appear at all, but this issue isn’t happening 100% of the time. Sometimes I will load the scene with this UI element, and it will appear completely fine.

I have tried using a number of different fonts, including both the default Arial, and custom .otf fonts, but they all exhibit the same behaviour. All of these fonts have been set to dynamic, as I assume is required for the canvas scaler to work on them.

The canvas that the UI elements are on is set to Screen Space - Overlay, and has a Canvas Scaler component attached.

Screenshots of the Canvas, Text, and Font: Imgur: The magic of the Internet

Edit: This problem goes away if I set the font to “Unicode” instead of “Dynamic”. Problem then is that the larger Text element fonts are being scaled up instead of actually increasing font size, causing blurry text. I can increase the size of the imported font to fix this, but it’s not exactly ideal.

Edit 2: Messed up font where text ISN’T missing, but the characters are incorrect. Imgur: The magic of the Internet
I think this may be the same problem, or at least a related issue.

Yeah, I found the problem, and came up with a solution that works - though it isn’t exactly ideal. Basically, the font atlas on device is getting full, and as far as I can tell is removing characters from the texture when it has to add new ones. Unfortunately the text.font.characterInfo list isn’t removing the characters from it’s list, so when requesting the characters for the text, it returns a valid character that isn’t actually in the atlas. I fixed it by clearing the character list in the font, and then manually requesting each character in my string with this piece of code, where “text” is a Unity UI Text component:

public void ResetText(bool deleteFontCharacterInfo = false)
{
	if (text)
	{
		if (deleteFontCharacterInfo)
		{
			text.font.characterInfo = null;
		}

		text.font.RequestCharactersInTexture(text.text,text.fontSize, text.fontStyle);
		text.FontTextureChanged();
	}
}

That being said, I believe that this was fixed in the recent Unity 5 update on Unity’s end.

So I came across this too and found a bug in the Unity UI code running with 5.4.0

It seemed to be caused by a bug whereby destroyed Text elements would not be removed from the FontUpdateTracker, then the FontUpdateTracker.RebuildForFont call would iterate forwards through the list, which would be modified while iterating through and miss some entries. I made a fix here and rebuilt the UnityEngine.UI solution and installed it in my system Unity folder at the location specified in the UI project.

https://bitbucket.org/bill_robinson/unityengine.ui/diff/UnityEngine.UI/UI/Core/FontUpdateTracker.cs?diff1=c614f7a5ae1a&diff2=0235856503a17667e97b4b985fe077cef292c588&at=5.4

It looks like the ‘vertical overflow’ is set to ‘truncate’. If you set it to ‘overflow’ it will probably fix it. I just came across this issue earlier and noticed setting font size > 25 made the text disappear. In your examples it seems to be the taller letters being cut off/truncated.

I had a similar problem with 3D Text, but seeing as there is no FontTextureChanged() function I had to improvise…

void Awake()
{
        textMesh = (TextMesh)GetComponent(typeof(TextMesh));
        resetChars();
        textMesh.text = "Ready";
}

void resetChars()
{
      textMesh.text = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
      textMesh.font.characterInfo = null;
      textMesh.font.RequestCharactersInTexture(textMesh.text, textMesh.fontSize, textMesh.fontStyle);
}

I was only making a limited prototype so I just added a basic charset but if you want a full solution you would need to add symbols and special characters (#,~…etc)