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.
  2. Dismiss Notice

MissingReferenceException: The variable m_AtlasTextures of TMP_FontAsset doesn't exist anymore.

Discussion in 'UGUI & TextMesh Pro' started by Tomer-Barkan, Jan 29, 2021.

  1. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    I'm getting this weird error sometimes in TMPro. It started after I upgraded from 2.0.1 to 2.1.3 and only when I use Chinese (but not English). Any ideas why?

    Full Error:

    MissingReferenceException: The variable m_AtlasTextures of TMP_FontAsset doesn't exist anymore.
    You probably need to reassign the m_AtlasTextures variable of the 'TMP_FontAsset' script in the inspector.
    UnityEngine.Texture.get_width () (at <526469d5a48c43eebd9af19f8745afa1>:0)
    TMPro.TMP_FontAsset.TryAddCharacterInternal (System.UInt32 unicode, TMPro.TMP_Character& character) (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMP_FontAsset.cs:2053)
    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@2.1.3/Scripts/Runtime/TMP_FontAssetUtilities.cs:159)
    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@2.1.3/Scripts/Runtime/TMP_FontAssetUtilities.cs:241)
    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@2.1.3/Scripts/Runtime/TMP_Text.cs:7320)
    TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] unicodeChars) (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMPro_UGUI_Private.cs:1190)
    TMPro.TMP_Text.ParseInputText () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMP_Text.cs:1892)
    TMPro.TMP_Text.GetPreferredWidth () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMP_Text.cs:4938)
    TMPro.TMP_Text.get_preferredWidth () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMP_Text.cs:1385)
    UnityEngine.UI.LayoutUtility+<>c.<GetPreferredWidth>b__4_1 (UnityEngine.UI.ILayoutElement e) (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/LayoutUtility.cs:76)
    UnityEngine.UI.LayoutUtility.GetLayoutProperty (UnityEngine.RectTransform rect, System.Func`2[T,TResult] property, System.Single defaultValue, UnityEngine.UI.ILayoutElement& source) (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/LayoutUtility.cs:168)
    UnityEngine.UI.LayoutUtility.GetLayoutProperty (UnityEngine.RectTransform rect, System.Func`2[T,TResult] property, System.Single defaultValue) (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/LayoutUtility.cs:137)
    UnityEngine.UI.LayoutUtility.GetPreferredWidth (UnityEngine.RectTransform rect) (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/LayoutUtility.cs:76)
    UnityEngine.UI.LayoutUtility.GetPreferredSize (UnityEngine.RectTransform rect, System.Int32 axis) (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/LayoutUtility.cs:36)
    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 C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/HorizontalOrVerticalLayoutGroup.cs:217)
    UnityEngine.UI.HorizontalOrVerticalLayoutGroup.CalcAlongAxis (System.Int32 axis, System.Boolean isVertical) (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/HorizontalOrVerticalLayoutGroup.cs:92)
    UnityEngine.UI.VerticalLayoutGroup.CalculateLayoutInputHorizontal () (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/VerticalLayoutGroup.cs:18)
    UnityEngine.UI.LayoutRebuilder+<>c.<Rebuild>b__12_0 (UnityEngine.Component e) (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/LayoutRebuilder.cs:84)
    UnityEngine.UI.LayoutRebuilder.PerformLayoutCalculation (UnityEngine.RectTransform rect, UnityEngine.Events.UnityAction`1[T0] action) (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/LayoutRebuilder.cs:147)
    UnityEngine.UI.LayoutRebuilder.PerformLayoutCalculation (UnityEngine.RectTransform rect, UnityEngine.Events.UnityAction`1[T0] action) (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/LayoutRebuilder.cs:144)
    UnityEngine.UI.LayoutRebuilder.PerformLayoutCalculation (UnityEngine.RectTransform rect, UnityEngine.Events.UnityAction`1[T0] action) (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/LayoutRebuilder.cs:144)
    UnityEngine.UI.LayoutRebuilder.Rebuild (UnityEngine.UI.CanvasUpdate executing) (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/Layout/LayoutRebuilder.cs:84)
    UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/CanvasUpdateRegistry.cs:177)
    UnityEngine.UI.ScrollRect:LateUpdate() (at C:/Program Files/Unity/Hub/Editor/2019.4.15f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/ScrollRect.cs:805)


     
  2. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    It was somehow resolved after making the atlas size smaller (reduced from 2048 to 1024). Multi atlas was on and remained on. Not sure why/how it happened, but it seems to have been happening whenever I was trying to show a specific font, other fonts worked fine.
     
  3. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    This can occur when the Glyph Table still references glyphs in at Atlas Index other than zero when for some odd reason those atlas textures are missing. Not sure how a font asset gets into that state.

    Resetting the Font Asset via the context menu or making any Generation Setting changes as you did which cause the equivalent of a reset will fix it.

    I still would like to figure out how / what leads a font asset to get into that stage.
     
  4. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    It happened to me a second time (and was an easy fix like you said - just forced it to reset the atlas). Again with Chinese. Maybe it has to do with the multi-atlas since Chinese has more characters?

    The first time it happened I looked at the atlas and there was only one, and it was completely full of glyphs (with mult-atlas enabled). So maybe something went wrong when it tried to create a new atlas, creating a reference that was never really populated.
     
  5. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    This feels like the new characters and glyphs are added to the font asset and most likely the additional atlas texture is also created but perhaps something goes wrong with the serialization where the additional atlas is not saved.

    Do you recall if this behavior re-appeared after a crash or closing Unity or something. I just need to figure out what gets the font asset in this state..
     
  6. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    Hmm, not a crash, but I think maybe both times it happened after I re-configured the font asset (changing the atlas size and/or enabling the multi-atlas) on one device, and then pulling these changes on another from the source control. Maybe that can point you in the right direction.
     
  7. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    See if repeating those steps reproduces the issue.

    Then if it does, see if saving the project or scene before pulling results in any changes to this behavior.
     
  8. Tomer-Barkan

    Tomer-Barkan

    Joined:
    Jul 31, 2012
    Posts:
    150
    I tired, It didn't happen again so far. But it's unlikely that I didn't save the scene, I have a tendency to press CTRL+S after every smallest change.
     
    Last edited: Jan 30, 2021
  9. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    350
    Resetting font assets doesn't fix it... The issue is 100% reproducible after entering play mode twice. I think there is something wrong with how atlas textures are created in play mode.. if you enable debug inspector and look at the array, you will likely see this incorrect state.

    Please fix, it should be easy to reproduce on 3.0.6 (I use font "NotoSerifJP-Medium" from google fonts and a bunch of Japanese text).

    For anyone looking for hack to work around the issue, here's what I did (call this for every font asset when entering play mode):
    Code (CSharp):
    1.  
    2.                             // Reset dynamic data to work around issue in TMP 3.0.6 in play mode.
    3.                             if (fontAsset.atlasPopulationMode == AtlasPopulationMode.Dynamic && fontAsset.isMultiAtlasTexturesEnabled)
    4.                             {
    5.                                 fontAsset.ClearFontAssetData();
    6.                                 // Force texture property to init to avoid another issue.
    7.                                 var unused = fontAsset.atlasTexture;
    8.                             }
     
    Last edited: Sep 14, 2021
    KKP0 likes this.
  10. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Are you using SRP (URP / HDRP)?

    If so, this issue was fixed in version 3.2.0-pre.1.

    Now if you are not using SRP, can you provide the step to reproduce or submit a bug report with project and steps?
     
  11. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    350
    Yes, the project uses URP. We will keep an eye for this fix when it comes out in the next stable version.
     
  12. BonjoCat

    BonjoCat

    Joined:
    Sep 5, 2020
    Posts:
    6
    Hi, i had this error, and fixed it:
    Steps to reproduce: japanese noto sans, and simplified chinese noto sans, set as a fallback in my main font. And when chinese words was used this error pops up, because they have same characters in some words(and all atlasses get mixed up or something like that)
    Fix: just dont use this two fonts as one fallback, i deleted chinese from fallback, and auto assigned chinese font to all texts when player changed language to chinese.
     
  13. Sabrino

    Sabrino

    Joined:
    Aug 8, 2015
    Posts:
    34
    The issue is not fixed in the latest preview. It keeps happening, so resetting is not a fix. Also with a Chinese font as fallback (not using a Japanese font as main font though). @Stephan_B
     
  14. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    The issue should no longer be occurring in version 3.2.0-pre.3 in terms of newly created font assets. However, if you have an existing font asset that still contains glyphs that reference to an invalid Atlas Index then this issue would remain until those font assets are updated. Since this are all likely to be Dynamic Font Assets, simply Reset them or use the use the Clear Dynamic Data option as seen below.

    upload_2022-9-14_14-7-22.png

    Let me know if this resolves your issue.
     
    cficara likes this.
  15. GoretQuiPoutre

    GoretQuiPoutre

    Joined:
    Jun 20, 2015
    Posts:
    3
    Hi,
    I encountered this issue this week in our project and made additional tests today to isolate the problem.

    We use multiple Google fonts for mutliple languages like japanese and chinese (simplified),
    I created multiple font assets, set to dynamic during the population and then switched to static once all texts in our game is set in the related font asset. We keep a dynamic fallback in case something were missing.

    In my case, I then added the dynamic font asset for chinese after the japanese one (see image 2) and started populating with chinese.
    The issue happens because some characters are shared between the two language and the japanese asset try to processes those characters AND the asset has the "Clear Dynamic Data On Build" checked AND the atlas texture is full. In this specific case, when try to create a new atlas texture, I got the error.
    When I unchecked the "Clear Dynamic Data On Build" option on the japanese dynamic fallback asset, the error didnt show up and a new atlas texture where created correctly.
    Is it an expected behaviour ? It might only be limited to editor as it's an option made for build.

    I created a small project with the font assets and the configuration, where I can reproduce it 100% when adding a specific character, I can share (~500MB).
    Also tried with the last 3.2.0-pre.3 and got the same behaviour, though I didnt recreate all the font asset I notice now :eek:.
     

    Attached Files:

    • 2.PNG
      2.PNG
      File size:
      89.5 KB
      Views:
      116
  16. Dreamdr

    Dreamdr

    Joined:
    Jun 16, 2022
    Posts:
    1
    I also encountered this bug, you just need to change the editor to English to fix it
     
  17. BonjoCat

    BonjoCat

    Joined:
    Sep 5, 2020
    Posts:
    6
    This is still occuring @Stephan_B , there is some new details in thread now. I think it can be fixed in future updates?
     
  18. cficara

    cficara

    Joined:
    Sep 27, 2017
    Posts:
    35
    Had this issue and the Reset options made the problem go away.
     
  19. vejab

    vejab

    Joined:
    Dec 21, 2021
    Posts:
    85
    I have this issue as well from time to time. You can solve it by doing the reset thing but eventually it comes back when the atlas gets too full again.