Search Unity

How to modify font asset's character sequence from scriptable object

Discussion in 'UGUI & TextMesh Pro' started by andrew_pearce_, Jan 15, 2021.

  1. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    169
    Hello,

    I have created simple custom editor script with scriptable object to checks font asset for missing characters (app is translated to Chinese and requires constant font asset update). Everything worked fine until recent TextMeshPro update (v1.4.1 and Unity 2018.4.28f1):

    Code (CSharp):
    1.   if (GUILayout.Button("Update Font Asset", GUILayout.Height(32))) {
    2.     fmso.UpdateFontAsset();
    3.     TMPro_FontAssetCreatorWindow.ShowFontAtlasCreatorWindow(fmso.GetFontAsset());
    4.   }
    5.  
    6.   ...
    7.  
    8.   [SerializeField]
    9.   private TMP_FontAsset fontAsset;
    10.   private List<char> requiredCharacterList = new List<char>();
    11.  
    12.   public void UpdateFontAsset() {
    13.     if (this.fontAsset == null) return;
    14.  
    15.     FontAssetCreationSettings facs = this.fontAsset.creationSettings;
    16.     // Characters from Font Asset or custom characater List
    17.     facs.characterSetSelectionMode = 7;
    18.     facs.characterSequence = string.Join("", this.requiredCharacterList);
    19.     // RenderModes: 0 = HintedSmooth for fast preview and 6 = DistanceField16 for final result
    20.     facs.renderMode = 0;
    21.  
    22.     this.fontAsset.creationSettings = facs;
    23.   }
    This code is no longer working. I am not able to change font asset's settings from my script. Even Character Set set via Font Asset Creator is not longer preserved. Instead, it is always reset to Unicode Range while I prefer Custom Characters. In addition, I am no longer able to modify characterSequence propery from my code.

    Is there any proper way I can modify FontAsset from my code and then open it Font Asset Creator (to regenerate it and save changes).

    Thanks, Andrew
     
    Last edited: Jan 15, 2021
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I will take a closer look tomorrow but which version of TMP did you upgrade to? Were you using 1.4.1 and are now using 1.5.3? or were you using an older version and now on 1.4.1?
     
  3. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    169
    Thanks and sorry for the delay with reply @Stephan_B. I checked and I was using "com.unity.textmeshpro": "1.3.0" and right now I am using "com.unity.textmeshpro": "1.4.1". Should I try to upgrade to 1.5.3? Here is how it looks:

    demo.gif

    I have created short demo with Korean font (as it contains less characters). I have selected custom character set, generated font asset and saved result. Then I selected another font (in editor) and then back Korean font. When I opened asset, its character set was reset back to Unicode Range. Also I would like to know how can I edit character set from code to add/remove characters.

    Thanks
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Definitely switch to 1.5.3 and then provide me if you can via PM the script you are using to generate your font asset so I can take a look at what API has changed and get you that info to get your script running again.
     
  5. andrew_pearce_

    andrew_pearce_

    Joined:
    Nov 5, 2018
    Posts:
    169
    @Stephan_B thanks, I switched to 1.5.3 but the problem remains the same. I created a small project with source script and sent you via PM. Thank you in advance!