Changing font asset and material at the same time for a language

More
2 weeks 4 days ago #4181 by joon
I figured it out.
My Font Assets were called "Lato-Bold SDF" and the material (with default name) was "Lato-Bold Atlas Material".
After understanding how it finds fonts from materials, I removed the " SDF" from the font asset name and it worked.

So... make sure your Material name fully includes the Font-asset name or it won't work.


Extra info:
I am doing this because of this crazy TMPRO behaviour, where you're not supposed to use the same material for World-space and Canvas-space fonts. digitalnativestudios.com/forum/index.php...94.msg11115#msg11115
If your fonts are not showing up in builds in some places, this is possibly the issue.

After identifying the issue, I made UI specific font materials, and tried to get I2Loc to assign them.
It didn't work, because this was returning null...
newFont = LocalizeTarget_TextMeshPro_Label.GetTMPFontFromMaterial(cmp, secondaryTranslation.EndsWith(newMat.name, StringComparison.Ordinal) ? secondaryTranslation : newMat.name);

in LocalizeTarget_TextMeshPro_UGUI. Digging into that helped me figure out that the font/material finding is based on a bunch of fragile string comparisons (not sure if it could be done better).




thanks fora great plugin, I've reviewed it 5 stars a long time ago :)

Please Log in or Create an account to join the conversation.

More
1 week 3 days ago #4185 by joon
I had another issue with this, where some texts end up with a FontAsset set to null.
This code prevents that from throwing errors and interrupting the localization event.
If you don't want to carefully control each of your text fields, but do it all via code, this can be helpful

//--[ Localize Font Material ]----------
                    Material newMat = cmp.GetSecondaryTranslatedObj<Material>(ref mainTranslation, ref secondaryTranslation);
                    if (mTarget.font == null)
                    {
                        newFont = LocalizeTarget_TextMeshPro_Label.GetTMPFontFromMaterial(cmp, secondaryTranslation.EndsWith(newMat.name, StringComparison.Ordinal) ? secondaryTranslation : newMat.name);
                        if (newFont != null)
                            LocalizeTarget_TextMeshPro_Label.SetFont(mTarget, newFont);
                        else
                            Debug.Log("Couldn't find font from material: " + newMat.name, mTarget.gameObject);
                    }

Please Log in or Create an account to join the conversation.

Time to create page: 0.242 seconds
Template by JoomlaShine