- Home /
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:
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: http://imgur.com/a/aSMyG
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. http://imgur.com/a/4p2Ct I think this may be the same problem, or at least a related issue.
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.
hi.. did you find the cause/solution? i'm finding the same odd random behaviour! also the latest 4.6.4 doesn't solve the bug
at the end i converted this text (i have hundreds of labels, and just one has this bug!) into a texture...
very very strange bug
ADDENDU$$anonymous$$: still having this but with latest Unity 4.6.7
Also happens in 5.3.2f1 with some iOS devices. Same random behaviour. Didn't try the solution below.
Answer by Projekt_Spartan · Apr 02, 2015 at 06:14 PM
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.
When are you actually calling this method? When do you ResetText? Is it on some event or is it purely manual?
Still happening. Could you clear when you are actually calling the method? Thanks in advance
Answer by Bill-Ape · Apr 25, 2017 at 10:07 AM
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.
How can I fix this without changing UI namespace classes? I tried to call FontUpdateTracker.UntrackText in OnDestroy function
Answer by cmarker_wilson · Jul 12, 2016 at 05:35 PM
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 could be mistaken, but I'm fairly sure that the vertical truncate will only work on a line-by-line basis, not letter-by-letter.
Regardless, this was not the issue. It was a problem with how letters were being added to the font atlas internally, and has since been fixed I believe.
Answer by kathryn-webb · Jul 22, 2016 at 03:41 PM
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)
Your answer
Follow this Question
Related Questions
Try to reproduce this Text UI element "bug" if you are developing for IOS 0 Answers
Text Meshes not rendering correctly on iOS device 1 Answer
How to change text on a TextMesh with a non-dynamic font on iOS? 2 Answers
IOS Unity 5 UI, Font/Text not displaying/Disappearing 3 Answers
Getting width of a character in new 4.6 UI system? 0 Answers