I am attempting to build my own Font fallback system for Label as the current one does not seem to work as described here . In my system, I would like to test a string letter by letter and if the current font does not have any characters, switch the whole Label to a more comprehensive backup font.
In theory this can be done with:
Font font = Resources.Load<Font>("Montserrat-ExtraBold");
string testString = "Telugu: ఈరోజు బయట వర్షం పడుతోంది."; //test phrase
foreach (char c in testString) {
bool hasChar = font.HasCharacter(c);
Debug.Log(c + " : " + hasChar); //will always return true unless font set to "Unicode"
}
However this doesn’t work.
Problem 1: Font.HasCharacter ALWAYS Returns True if Font is Dynamic
It returns true for all characters, even the ones it blatantly can’t display and doesn’t have. The above is a special string of Telugu (an Indian language) that is most definitely not covered, and yet it will debug saying true for every single character, even the Telugu ones it can’t display.
Applying this “testString” to a Label and putting in on screen with that Font proves it cannot display these characters either, yet it will still return “true” for all.
The only way I can see to get the correct output is to set the Font to Unicode. Then Debugs out correctly that it does not have the Telugu characters.
Problem 2: Many Fonts MUST Be Set Dynamic or They Don’t Work At All
However, this creates another problem as it seems Montserrat and a few other fonts I tested cannot display anything unless they are set to Dynamic.
If I set the Font to Unicode or ASCII and restart the program (must be restarted to register the change - perhaps another issue), a Label displaying any strings with this Font goes blank.
Solution?
The only workaround I just thought of is to add TWO copies of each Font - one set to Unicode (so it will output the right Font.HasCharacter) and another set to Dynamic (which is used for the Labels so it can actually work). This works, but this is crazy isn’t it?
Either Font.HasCharacter should work in Dynamic (ideally) and/or normal common Fonts should still work when they are not set to Dynamic.
I presume Font.HasCharacter should also NOT check the fallback fonts in its operation if in Dynamic mode or this will also not give you the useful information you would usually want. (I have no way to test to see if it does though as it doesn’t work at all.)
Is this a known issue? Is there something I’m missing? I can submit a bug report. Thanks.