I want to display all languages with TextMeshPro

Unity 2020.1.1f1
TextMeshPro 3.0.1

I put the Arial font in my project and created an SDF asset file with Ctrl+Shift+F12.
In UI → Text-TextMeshPro, the ARIAL SDF file created earlier was specified as Font Asset, and Atlas Population Mode on the SDF inspector was also changed to Dynamic.

The problem here is that the characters that are displayed are not displayed even if words from various countries such as Japanese, Korean, Russian, and Thai are entered.

The characters input by inputtext as shown in the source code below are divided for each character in the “SetCharactersToFontAsset” function, but most characters come back as missingUnicodes and cannot display all characters. Hmm.

For example, in UI→Text, Font can be Arial and can display characters mixed in multiple languages.
I thought that based on the Arial font, it would be possible to create characters in real time like the source code.

What is the cause of unexpected disappointment?
Thank you.

public TMP_FontAsset font;
private TextMeshProUGUI textbox_name;

    // Start is called before the first frame update
    void Start()
    {
        try
        {
            textbox_name = this.GetComponent<TextMeshProUGUI>();

            ↓ Because it was an error when creating a thread
            string inputtext   = "UI_TMP" + "\n" +
                                "Written as coronavirus in Japanese" + "\n" +
                                "Corona virus in Korean" + "\n" +
                                "Coronavirus in Russian" + "\n" +
                                "Coronavirus is written in Thai";

            SetCharactersToFontAsset(font, inputtext);

            textbox_name.text = inputtext;
        }
        catch (Exception ex)
        {
            string re = ex.ToString();
        }
    }

    void SetCharactersToFontAsset(TMP_FontAsset font, string text)
    {
        try
        {
            HashSet<char> hashSet   = new HashSet<char>(text.ToCharArray());
            uint[] addCharacters    = new uint[hashSet.Count];
            uint[] missingUnicodes  = new uint[hashSet.Count];

            int n = 0;
            foreach (char c in hashSet)
            {
                addCharacters[n++] = c;
            }

            font.ClearFontAssetData();

            font.TryAddCharacters(addCharacters, out missingUnicodes);
        }
        catch (Exception ex)
        {
            string re = ex.ToString();
        }
    }

The Arial font file does not contain Chinese, Japanese or Korean characters. As such, unless you create a dynamic font asset from a font file that has coverage for those languages, you will get the missing glyph (square) glyph.

The reason, they should up with UI Text is because the Legacy text system fallbacks back to some system font (without the knowledge of the user) which is why these character show up thus making user think Arial contains those characters when it does not.

In order to display characters for any given language, you need to use a font file that has coverage for those languages.

See the following two videos which shows how you can create a dynamic font asset able to display every single character contained in a font file. Selecting the right font file for the given language is the first step.

1 Like

Thank you, it’s resolved!
I was able to view the videos on Youtube and display them in Japanese, Korean, Thai, etc.
I will add settings to Fallback Font Assets for the languages I want to display.