Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug Chinese character 世 breaks text when using fallback font in editor

Discussion in 'UGUI & TextMesh Pro' started by Kamyker, Jun 9, 2021.

  1. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,061
    My setup is:

    1. Main font asset is English only
    2. Bunch of other fonts as fallback (including NotoSansSC-Medium)


    Everything works fine, some characters are missing and shown as squares but this 世 breaks text field completely. It works fine when NotoSansSC is set as font for tmp_text component.

    #edit
    Works fine in built game so only happens in editor.
     
    Last edited: Jun 9, 2021
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    I would need to get a repro project to figure out why this is behaving differently in the Editor vs. Build.

    Make sure you are using the latest release of TMP. I behavior persists, please submit a bug report with project so I can take a closer look.
     
  3. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,061
    I'm using the newest one (3.0.6). Will make repro project if I find some time.
     
  4. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,061
    After releasing update with 3.0.6 (previous one was using 3.0.3) there's a lot more errors in built game:





    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object.: TMPro.TMP_FontAsset.TryAddCharacterInternal (System.UInt32 unicode, TMPro.TMP_Character& character) (at <00000000000000000000000000000000>:0) TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAsset_Internal (System.UInt32 unicode, TMPro.TMP_FontAsset sourceFontAsset, System.Boolean includeFallbacks, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isAlternativeTypeface) (at <00000000000000000000000000000000>:0) TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAssets (System.UInt32 unicode, TMPro.TMP_FontAsset sourceFontAsset, System.Collections.Generic.List`1[T] fontAssets, System.Boolean includeFallbacks, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isAlternativeTypeface) (at <00000000000000000000000000000000>:0) TMPro.TMP_Text.GetTextElement (System.UInt32 unicode, TMPro.TMP_FontAsset fontAsset, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isUsingAlternativeTypeface) (at <00000000000000000000000000000000>:0) TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] unicodeChars) (at <00000000000000000000000000000000>:0) TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at <00000000000000000000000000000000>:0) TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at <00000000000000000000000000000000>:0) UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at <00000000000000000000000000000000>:0) System.Runtime.Remoting.Contexts.CrossContextDelegate.Invoke () (at <00000000000000000000000000000000>:0) System.Runtime.Remoting.Contexts.CrossContextDelegate:Invoke() (224)
    Code (CSharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object.: TMPro.TMP_FontAsset.TryAddCharacterInternal (System.UInt32 unicode, TMPro.TMP_Character& character) (at <00000000000000000000000000000000>:0) TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAsset_Internal (System.UInt32 unicode, TMPro.TMP_FontAsset sourceFontAsset, System.Boolean includeFallbacks, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isAlternativeTypeface) (at <00000000000000000000000000000000>:0) TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAssets (System.UInt32 unicode, TMPro.TMP_FontAsset sourceFontAsset, System.Collections.Generic.List`1[T] fontAssets, System.Boolean includeFallbacks, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isAlternativeTypeface) (at <00000000000000000000000000000000>:0) TMPro.TMP_Text.GetTextElement (System.UInt32 unicode, TMPro.TMP_FontAsset fontAsset, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isUsingAlternativeTypeface) (at <00000000000000000000000000000000>:0) TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] unicodeChars) (at <00000000000000000000000000000000>:0) TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at <00000000000000000000000000000000>:0) TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at <00000000000000000000000000000000>:0) UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at <00000000000000000000000000000000>:0) System.Runtime.Remoting.Contexts.CrossContextDelegate.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.UI.ScrollRect.LateUpdate () (at <00000000000000000000000000000000>:0) UnityEngine.UI.ScrollRect:LateUpdate() (65)
    3.  
    Code (CSharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object.: TMPro.TMP_MaterialManager.GetFallbackMaterial (TMPro.TMP_FontAsset fontAsset, UnityEngine.Material sourceMaterial, System.Int32 atlasIndex) (at <00000000000000000000000000000000>:0) TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] unicodeChars) (at <00000000000000000000000000000000>:0) TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at <00000000000000000000000000000000>:0) TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at <00000000000000000000000000000000>:0) UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at <00000000000000000000000000000000>:0) System.Runtime.Remoting.Contexts.CrossContextDelegate.Invoke () (at <00000000000000000000000000000000>:0) System.Runtime.Remoting.Contexts.CrossContextDelegate:Invoke() (27)
    Code (CSharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object.: TMPro.TMP_MaterialManager.GetFallbackMaterial (TMPro.TMP_FontAsset fontAsset, UnityEngine.Material sourceMaterial, System.Int32 atlasIndex) (at <00000000000000000000000000000000>:0) TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] unicodeChars) (at <00000000000000000000000000000000>:0) TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at <00000000000000000000000000000000>:0) TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at <00000000000000000000000000000000>:0) UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at <00000000000000000000000000000000>:0) System.Runtime.Remoting.Contexts.CrossContextDelegate.Invoke () (at <00000000000000000000000000000000>:0) UnityEngine.UI.ScrollRect.LateUpdate () (at <00000000000000000000000000000000>:0) UnityEngine.UI.ScrollRect:LateUpdate() (18)
     
  5. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,061
    Hmm I've changed from 3 separate fallback fonts (sc, jp, ch) to single NotoSansCJK and errors are gone.

    Well, let's say that's fixed.
     
    DonPuno likes this.
  6. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,061
    Got similar issue again, this time I had to Clear Dynamic Data. Error said that
    m_AtlasTextures[m_AtlasTextureIndex]
    is null in
    TryAddCharacterInternal
    . Text asset had 2 full atlas textures and it seemed like 3rd one wasn't created but somehow m_AtlasTextureIndex was pointing there.
     
  7. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,061
    I think i found what causes it. In TMP_FontAsset.cs SetupNewAtlasTexture():
    Code (CSharp):
    1.             #if UNITY_EDITOR
    2.             // Add new texture as sub asset to font asset
    3.             if (UnityEditor.EditorUtility.IsPersistent(this))
    4.             {
    5.                 Texture2D tex = m_AtlasTextures[m_AtlasTextureIndex];
    6.                 tex.name = m_AtlasTexture.name + " " + m_AtlasTextureIndex;
    7.  
    8.                 UnityEditor.AssetDatabase.AddObjectToAsset(m_AtlasTextures[m_AtlasTextureIndex], this);
    9.                 TMP_EditorResourceManager.RegisterResourceForReimport(this);
    10.             }
    11.             #endif
    m_AtlasTexture is null, shouldn't it use atlasTexture (that sets m_AtlasTexture when it's null) ?


    Code (CSharp):
    1. UnassignedReferenceException: The variable m_AtlasTexture of TMP_FontAsset has not been assigned.
    2. You probably need to assign the m_AtlasTexture variable of the TMP_FontAsset script in the inspector.
    3. UnityEngine.Object.get_name () (at <127e81e1cb3441cc97d26b1910daae77>:0)
    4. TMPro.TMP_FontAsset.SetupNewAtlasTexture () (at Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_FontAsset.cs:2416)
    5. TMPro.TMP_FontAsset.TryAddCharacterInternal (System.UInt32 unicode, TMPro.TMP_Character& character) (at Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_FontAsset.cs:2118)
    6. TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAsset_Internal (System.UInt32 unicode, TMPro.TMP_FontAsset sourceFontAsset, System.Boolean includeFallbacks, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isAlternativeTypeface) (at Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_FontAssetUtilities.cs:159)
    7. TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAssets (System.UInt32 unicode, TMPro.TMP_FontAsset sourceFontAsset, System.Collections.Generic.List`1[T] fontAssets, System.Boolean includeFallbacks, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isAlternativeTypeface) (at Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_FontAssetUtilities.cs:241)
    8. TMPro.TMP_Text.GetTextElement (System.UInt32 unicode, TMPro.TMP_FontAsset fontAsset, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isUsingAlternativeTypeface) (at Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_Text.cs:6147)
    9. TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] unicodeChars) (at Packages/com.unity.textmeshpro/Scripts/Runtime/TMPro_UGUI_Private.cs:1209)
    10. TMPro.TMP_Text.ParseInputText () (at Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_Text.cs:1902)
    11. TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at Packages/com.unity.textmeshpro/Scripts/Runtime/TMPro_UGUI_Private.cs:1644)
    12. TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Packages/com.unity.textmeshpro/Scripts/Runtime/TextMeshProUGUI.cs:216)
    13. UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/CanvasUpdateRegistry.cs:217)
    14. UnityEngine.Canvas:SendWillRenderCanvases()
     
  8. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Are you able to reproduce the behavior that leads to this issue?

    Can you reproduce this with any font asset and what are the steps to get it into that state?
     
  9. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,061
    No but found something that could be related, when I reset tmp asset (and internally new assets are added) reimport doesn't occur as TMP_EditorResourceManager uses Camera.onPostRender that isn't called in URP/HDRP.
     
  10. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Great catch!

    This would explain why some of the font asset data like newly added glyphs which may be referencing those additional atlas textures is serialized but not the additional textures.

    I will try taking a closer look at this over the next day or so and follow up once I have more information.
     
    Last edited: Jun 30, 2021
    Kamyker likes this.
  11. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,061
    Hi, any news? This bug also happens when Unity crashes in playmode and then I have to restart font asset every time.
     
  12. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    I did make the relevant changes to make sure the added atlas texture get serialized when using SRP.

    In terms of potential atlas textures not getting serialized correctly when Unity crashes, I will have to do some additional testing on this. I think that it should be fine with the new changes as the crash would have to occur just as we added a new atlas texture and then before the end of that same frame have Unity crash.
     
    Last edited: Aug 6, 2021
  13. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,061
    Ok thanks, waiting for 3.0.7.
     
  14. pfay

    pfay

    Joined:
    Mar 2, 2020
    Posts:
    7
    I had this same issue in Unity 2019.4.21f1 on TMP 2.1.6 (should be equiv of 3.0.6). Not sure how I got into that state. For me, doing a reset left dangling textures - it would reset the first texture, and delete all references in the TMP font asset (verified by looking at the asset file), but it retained subsequent textures attached to the object just hanging there. Not sure if those would have caused issues explicitly, but I reset all my dynamic textures using this custom reset logic that I triggered from an editor menu:


    Code (CSharp):
    1.         // dynamicFonts should be some list of the fonts you want to reset
    2.         private static void ResetDynamicFontTextures(List<TMP_FontAsset> dynamicFonts)
    3.         {
    4.             foreach (var font in dynamicFonts)
    5.             {
    6.                 var objectsToKeep = new List<UnityEngine.Object>()
    7.                 {
    8.                     font.atlasTexture,
    9.                     font.material
    10.                 };
    11.                DeleteSubObjects(font, objectsToKeep);
    12.                 font.ClearFontAssetData();
    13.             }
    14.             AssetDatabase.SaveAssets();
    15.         }
    16.  
    17.  
    18.         // Delete any old sub objects inside a main asset.
    19.         // https://forum.unity.com/threads/assetdatabase-missing-functionality-to-remove-null-sub-objects.660856/#post-5671102
    20.         public static void DeleteSubObjects(UnityEngine.Object mainAsset, List<UnityEngine.Object> objectsToKeep = null)
    21.         {
    22.             UnityEngine.Object[] assets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(mainAsset));
    23.             foreach(UnityEngine.Object obj in assets)
    24.             {
    25.                 if ( obj == null ||
    26.                      ( ! AssetDatabase.IsMainAsset(obj) &&
    27.                        ! (obj is GameObject) &&
    28.                        ! (obj is Component) &&
    29.                        ! (objectsToKeep != null && objectsToKeep.Contains(obj))
    30.                      )
    31.                 )
    32.                     UnityEngine.Object.DestroyImmediate(obj, true);
    33.             }
    34.         }
     
  15. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    This issue was due to OnPostRender not getting called when using SRP (URP / HDRP). This was causing the changes to the font asset to get serialized but not the atlas textures. As such, you would end up with glyphs potentially referencing some atlas texture index greater than zero which exceeded the atlas texture array size.

    This fix for this issue is included in version 2.2.0-preview.1 of the TMP package for Unity 2019.4 and version 3.2.0-pre.1 for Unity 2020.3 or newer.
     
  16. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,061
    Still getting similar error in 3.2.0-pre2

    Code (CSharp):
    1. MissingReferenceException: The variable m_AtlasTextures of TMP_FontAsset doesn't exist anymore.
    2. You probably need to reassign the m_AtlasTextures variable of the 'TMP_FontAsset' script in the inspector.
    3. UnityEngine.Object.get_name () (at <0ee480759f3d481d82ada245dc74f9fd>:0)
    4. TMPro.TMP_MaterialManager.GetFallbackMaterial (TMPro.TMP_FontAsset fontAsset, UnityEngine.Material sourceMaterial, System.Int32 atlasIndex) (at Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_MaterialManager.cs:370)
    5. TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] unicodeChars) (at Packages/com.unity.textmeshpro/Scripts/Runtime/TMPro_UGUI_Private.cs:1323)
    6. TMPro.TMP_Text.ParseInputText () (at Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_Text.cs:1946)
    7. TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at Packages/com.unity.textmeshpro/Scripts/Runtime/TMPro_UGUI_Private.cs:1636)
    8. TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Packages/com.unity.textmeshpro/Scripts/Runtime/TextMeshProUGUI.cs:216)
    9. UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/CanvasUpdateRegistry.cs:215)
    10. UnityEngine.Canvas:SendWillRenderCanvases()
    Or
    Code (CSharp):
    1. UnassignedReferenceException: The variable m_AtlasTexture of TMP_FontAsset has not been assigned.
    2. You probably need to assign the m_AtlasTexture variable of the TMP_FontAsset script in the inspector.
    3. UnityEngine.Object.get_name () (at <0ee480759f3d481d82ada245dc74f9fd>:0)
    4. TMPro.TMP_FontAsset.SetupNewAtlasTexture () (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMP_FontAsset.cs:2781)
    5. TMPro.TMP_FontAsset.TryAddCharacterInternal (System.UInt32 unicode, TMPro.TMP_Character& character) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMP_FontAsset.cs:2499)
    6. TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAsset_Internal (System.UInt32 unicode, TMPro.TMP_FontAsset sourceFontAsset, System.Boolean includeFallbacks, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isAlternativeTypeface) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMP_FontAssetUtilities.cs:158)
    7. TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAssets (System.UInt32 unicode, TMPro.TMP_FontAsset sourceFontAsset, System.Collections.Generic.List`1[T] fontAssets, System.Boolean includeFallbacks, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isAlternativeTypeface) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMP_FontAssetUtilities.cs:240)
    8. TMPro.TMP_Text.GetTextElement (System.UInt32 unicode, TMPro.TMP_FontAsset fontAsset, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isUsingAlternativeTypeface) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMP_Text.cs:6362)
    9. TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] textProcessingArray) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMPro_UGUI_Private.cs:1194)
    10. TMPro.TMP_Text.ParseInputText () (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMP_Text.cs:1948)
    11. TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMPro_UGUI_Private.cs:1683)
    12. TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TextMeshProUGUI.cs:216)
    13. UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/CanvasUpdateRegistry.cs:215)
    14. UnityEngine.Canvas:ForceUpdateCanvases()
     
    Last edited: Jan 20, 2022
  17. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    If your exiting font assets include glyphs that are pointing to an invalid index, regenerating those font assets should resolve this issue which then should no longer occur.

    If you have regenerated those font assets or if they are dynamic used the "Reset" option / "Clear Dynamic Data on Build" and it is still happening then this could be something else. If so, are you able to reproduce it?
     
  18. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,061
    Yes I'm using dynamic font. Tried resetting asset and Unity, a bit different log this time:
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. TMPro.TMP_FontAsset.SetupNewAtlasTexture () (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMP_FontAsset.cs:2781)
    3. TMPro.TMP_FontAsset.TryAddCharacterInternal (System.UInt32 unicode, TMPro.TMP_Character& character) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMP_FontAsset.cs:2499)
    4. TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAsset_Internal (System.UInt32 unicode, TMPro.TMP_FontAsset sourceFontAsset, System.Boolean includeFallbacks, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isAlternativeTypeface) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMP_FontAssetUtilities.cs:158)
    5. TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAssets (System.UInt32 unicode, TMPro.TMP_FontAsset sourceFontAsset, System.Collections.Generic.List`1[T] fontAssets, System.Boolean includeFallbacks, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isAlternativeTypeface) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMP_FontAssetUtilities.cs:240)
    6. TMPro.TMP_Text.GetTextElement (System.UInt32 unicode, TMPro.TMP_FontAsset fontAsset, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isUsingAlternativeTypeface) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMP_Text.cs:6362)
    7. TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] textProcessingArray) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMPro_UGUI_Private.cs:1194)
    8. TMPro.TMP_Text.ParseInputText () (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMP_Text.cs:1948)
    9. TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TMPro_UGUI_Private.cs:1683)
    10. TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.2/Scripts/Runtime/TextMeshProUGUI.cs:216)
    11. UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/CanvasUpdateRegistry.cs:215)
    12. UnityEngine.Canvas:ForceUpdateCanvases()

    I think I found a fix, changed package to local again and basically "m_AtlasTexture" is null as it's never set. Changed it to "atlasTexture" and that was enough as it does:
    Code (CSharp):
    1. get
    2. {
    3.     if (m_AtlasTexture == null)
    4.     {
    5.         m_AtlasTexture = atlasTextures[0];
    6.     }
    7.     return m_AtlasTexture;
    8. }
    New atlas is finally added:



    Btw this is the only place where m_AtlasTexture is used, everywhere else it's atlasTexture so I guess that's correct fix.
    Code (CSharp):
    1.         void SetupNewAtlasTexture()
    2.         {
    3.             (...)
    4.  
    5.             #if UNITY_EDITOR
    6.             // Add new texture as sub asset to font asset
    7.             Texture2D tex = m_AtlasTextures[m_AtlasTextureIndex];
    8.             //old tex.name = m_AtlasTexture.name + " " + m_AtlasTextureIndex;
    9.             tex.name = atlasTexture.name + " " + m_AtlasTextureIndex;
    10.        
    11.             OnFontAssetTextureChanged?.Invoke(tex, this);
    12.             #endif
    13.         }
     
  19. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,061
    Bump, making sure you read this @Stephan_B . Didn't have any errors after the change above.
     
  20. SniperED007

    SniperED007

    Joined:
    Sep 29, 2013
    Posts:
    331
    I'm still getting this error in the editor (unrelated to the specific character, happening to me for Japanese characters)
    UnassignedReferenceException: The variable m_AtlasTexture of TMP_FontAsset has not been assigned.

    TMP: 3.0.6
    Unity: 2022.1.24f1

    I haven't taken made the code changes above mentioned above.
    I'm using fallback fonts and have Multi Atlas Texture enabled on the Fallback font.

    Code (CSharp):
    1. UnassignedReferenceException: The variable m_AtlasTexture of TMP_FontAsset has not been assigned.
    2. You probably need to assign the m_AtlasTexture variable of the TMP_FontAsset script in the inspector.
    3. UnityEngine.Object.get_name () (at <3b18519be5f3486abcce4fd34ea6dcd9>:0)
    4. TMPro.TMP_FontAsset.SetupNewAtlasTexture () (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_FontAsset.cs:2415)
    5. TMPro.TMP_FontAsset.TryAddCharacterInternal (System.UInt32 unicode, TMPro.TMP_Character& character) (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_FontAsset.cs:2118)
    6. TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAsset_Internal (System.UInt32 unicode, TMPro.TMP_FontAsset sourceFontAsset, System.Boolean includeFallbacks, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isAlternativeTypeface) (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_FontAssetUtilities.cs:159)
    7. TMPro.TMP_FontAssetUtilities.GetCharacterFromFontAssets (System.UInt32 unicode, TMPro.TMP_FontAsset sourceFontAsset, System.Collections.Generic.List`1[T] fontAssets, System.Boolean includeFallbacks, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isAlternativeTypeface) (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_FontAssetUtilities.cs:241)
    8. TMPro.TMP_Text.GetTextElement (System.UInt32 unicode, TMPro.TMP_FontAsset fontAsset, TMPro.FontStyles fontStyle, TMPro.FontWeight fontWeight, System.Boolean& isUsingAlternativeTypeface) (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_Text.cs:6147)
    9. TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] unicodeChars) (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMPro_UGUI_Private.cs:1209)
    10. TMPro.TMP_Text.ParseInputText () (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_Text.cs:1902)
    11. TMPro.TMP_Text.GetPreferredWidth () (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_Text.cs:3755)
    12. TMPro.TMP_Text.get_preferredWidth () (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_Text.cs:1384)
    13. UnityEngine.UI.LayoutUtility+<>c.<GetPreferredWidth>b__4_1 (UnityEngine.UI.ILayoutElement e) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Layout/LayoutUtility.cs:68)
    14. UnityEngine.UI.LayoutUtility.GetLayoutProperty (UnityEngine.RectTransform rect, System.Func`2[T,TResult] property, System.Single defaultValue, UnityEngine.UI.ILayoutElement& source) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Layout/LayoutUtility.cs:161)
    15. UnityEngine.UI.LayoutUtility.GetLayoutProperty (UnityEngine.RectTransform rect, System.Func`2[T,TResult] property, System.Single defaultValue) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Layout/LayoutUtility.cs:129)
    16. UnityEngine.UI.LayoutUtility.GetPreferredWidth (UnityEngine.RectTransform rect) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Layout/LayoutUtility.cs:68)
    17. UnityEngine.UI.LayoutUtility.GetPreferredSize (UnityEngine.RectTransform rect, System.Int32 axis) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Layout/LayoutUtility.cs:31)
    18. UnityEngine.UI.HorizontalOrVerticalLayoutGroup.GetChildSizes (UnityEngine.RectTransform child, System.Int32 axis, System.Boolean controlSize, System.Boolean childForceExpand, System.Single& min, System.Single& preferred, System.Single& flexible) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Layout/HorizontalOrVerticalLayoutGroup.cs:233)
    19. UnityEngine.UI.HorizontalOrVerticalLayoutGroup.CalcAlongAxis (System.Int32 axis, System.Boolean isVertical) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Layout/HorizontalOrVerticalLay
     
    Last edited: Jan 19, 2023