Search Unity

TextMesh Pro TMPro SubMeshUI Error when changing scenes

Discussion in 'UGUI & TextMesh Pro' started by GustavNinja, Jun 22, 2021.

  1. GustavNinja

    GustavNinja

    Joined:
    Jun 13, 2016
    Posts:
    96
    My game recently updated to Unity 2019.4.28f1 and we added the latest TMPro 2.1.6 as well. What we have noticed is that we have been getting a lot of errors from SubMeshUI when leaving a scene but it's hard to reproduce and I haven't been able to reproduce it but my game gets 5000 errors a day. So it's basically when we open a scene and that scene contains a fallback character. When exiting the scene the error occurs.
    In my code we also do a specific Destroy certain GameObjects that has been Instantiated when leaving the scene. But even if I remove this part it seems to occur.

    Errors
    Code (CSharp):
    1. TMPro.TMP_SubMeshUI.UpdateMaterial () (at <00000000000000000000000000000000>:0)
    2. TMPro.TMP_SubMeshUI.SetMaterialDirty () (at <00000000000000000000000000000000>:0)
    3. UnityEngine.UI.MaskableGraphic.OnDisable () (at <00000000000000000000000000000000>:0)
    4. TMPro.TMP_SubMeshUI.OnDisable () (at <00000000000000000000000000000000>:0)
    By checking the code part it can be easily fixed with adding a null check for the fontsharedMaterial in UpdateMaterial but I was wondering why this might be occurring anyway?
    Code (CSharp):
    1.             if (m_sharedMaterial.HasProperty(ShaderUtilities.ShaderTag_CullMode))
    2.             {
    3.                 if (textComponent.fontSharedMaterial)
    4.                 {
    5.                     float cullMode = textComponent.fontSharedMaterial.GetFloat(ShaderUtilities.ShaderTag_CullMode);
    6.                     m_sharedMaterial.SetFloat(ShaderUtilities.ShaderTag_CullMode, cullMode);
    7.                 }
    8.             }
    Any help would be much appreciated.
     
    Last edited: Jun 22, 2021
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I'll take a look to see if I can reproduce this behavior.

    Sub Text objects are no longer serialized so maybe if you have existing prefabs where sub text objects were serialized before, it might be leading to this behavior?
     
  3. GustavNinja

    GustavNinja

    Joined:
    Jun 13, 2016
    Posts:
    96
    I changed a lot in the Unity update but I searched all the scenes to remove all submeshui and updated all the serialization in my scenes. Most of the text get set in code so it creates a submesh during runtime.

    It might have something to do with unloading FontAssets between scene switches but I do a comparison between the scenes to check what assets are to remain so that I don't reload used AssetBundle files.

    * Upon checking if my FontAssets and FontAsset materials get unloaded or not. They remain when switching scenes since they are in the next scene as well.
     
    Last edited: Jun 22, 2021
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Adding the null check will certainly avoid the error. However, the real challenge is figuring why the font asset used by the text object ends up null. Let me know if you are able to reproduce the issue. I will add the null check there but would love to figure out the root cause.
     
  5. GustavNinja

    GustavNinja

    Joined:
    Jun 13, 2016
    Posts:
    96
    I can get a somewhat resembling error but not entirely like our players so I'll give you an example later today when I get some time. Thank you for the quick response.
     
  6. GustavNinja

    GustavNinja

    Joined:
    Jun 13, 2016
    Posts:
    96
    @Stephan_B

    I managed to create a simple project that reproduces it in the only way I currently know. AssetBundle.UnloadAllAssetBundles(true) will cause the Exception upon exiting an Assetbundle scene.

    Project added in post

    1. Open Start scene
    2. Press Initialize button then select whatever scene you want to go to.
    3. Then press the return to Start button and the error occurs.

    While my players are experiencing this error when getting another error and chooses to reboot to the first scene. When switching between scenes which most of my players are experiencing are somewhat similar but unloading assets in between scenes. I have not managed to reproduce this yet in editor nor game and other testers has not been able to reproduce this yet. But it ought to have something todo with AssetBundle.Unload function. Even though I'm not unloading the FontAsset nor Material but for some reason players gets the error.

    *I made it with 2019.4.14f1 but newer version also causes it. I'm mainly working on 2019.4.28f1

    Hope this helps.
     

    Attached Files:

    Stephan_B likes this.
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Thank you for providing the repro project.

    I'll try looking into this over the next few days and follow up thereafter.
     
    GustavNinja likes this.
  8. GustavNinja

    GustavNinja

    Joined:
    Jun 13, 2016
    Posts:
    96
    Thank you. I look forward to your response.
     
  9. GustavNinja

    GustavNinja

    Joined:
    Jun 13, 2016
    Posts:
    96
    @Stephan_B
    I updated the game this week with a new release by adding the null check and all errors disappeared from the game and people don't seem to report any problems within the game so far. Just would like to update you on that with this. I will keep this part for now until you have found a proper solution.
     
  10. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Thank you for the update.

    I'll make sure this issue is addressed in the next release.
     
    GustavNinja likes this.
  11. youngmins

    youngmins

    Joined:
    Sep 10, 2021
    Posts:
    1
    Is this an unresolved issue yet?
    Still having the same problem as above.

    Reported to Firebase Crashlytics. (iOS only)
    Non-fatal Exception: NullReferenceException
    0 ??? 0x0 UpdateMaterial (TMPro.TMP_SubMeshUI)
    1 ??? 0x0 SetMaterialDirty (TMPro.TMP_SubMeshUI)
    2 ??? 0x0 OnDisable (UnityEngine.UI.MaskableGraphic)
    3 ??? 0x0 OnDisable (TMPro.TMP_SubMeshUI)

    Unity: 2021.1.11f1
    TextMeshPro: 3.0.6
     
  12. Nyankoooo

    Nyankoooo

    Joined:
    May 21, 2016
    Posts:
    144
    @Stephan_B Still seeing this too (Crashlytics only):

    Code (CSharp):
    1. Non-fatal Exception: java.lang.Exception: NullReferenceException : Object reference not set to an instance of an object.
    2.        at TMPro.TMP_SubMeshUI.UpdateMaterial(TMPro.TMP_SubMeshUI)
    3.        at TMPro.TMP_SubMeshUI.SetMaterialDirty(TMPro.TMP_SubMeshUI)
    4.        at UnityEngine.UI.MaskableGraphic.OnDisable(UnityEngine.UI.MaskableGraphic)
    5.        at TMPro.TMP_SubMeshUI.OnDisable(TMPro.TMP_SubMeshUI)
    Unity: 2020.3.26f1
    TMP: 3.0.6
    Build Target: Android
     
  13. wqaetly

    wqaetly

    Joined:
    Oct 25, 2018
    Posts:
    7
    Code (CSharp):
    1. Object reference not set to an instance of an object
    2.  
    3. TMPro.TMP_SubMeshUI.UpdateMaterial () (at <00000000000000000000000000000000>.0)
    4. TMPro.TMP_SubMeshUI.SetMaterialDirty () (at <00000000000000000000000000000000>.0)
    5. UnityEngine.UI.MaskableGraphic.OnDisable () (at <00000000000000000000000000000000>.0)
    6. TMPro.TMP_SubMeshUI.OnDisable () (at <00000000000000000000000000000000>.0)
    Unity: 2020.3.16f1
    TMP: 3.0.6
    Build Target: Android

    @Stephan_B Still seeing this too
     
  14. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I would suggest testing with the latest release of the TMP package which is version 3.2.0-pre.3 to see if the issue persists.

    If the issue persists with this new release then please submit a bug report with project and I'll be more than happy to take a closer look.
     
  15. jdell64

    jdell64

    Joined:
    Mar 15, 2017
    Posts:
    13
    Faced same issue... just kinda cropped up. I updated to 3.2.0 and it still persists:


    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. TMPro.TMP_SubMeshUI.UpdateMaterial () (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.3/Scripts/Runtime/TMP_SubMeshUI.cs:710)
    3. TMPro.TMP_SubMeshUI.SetMaterialDirty () (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.3/Scripts/Runtime/TMP_SubMeshUI.cs:617)
    4. UnityEngine.UI.MaskableGraphic.OnValidate () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/MaskableGraphic.cs:202)
    I also tried going to 4.0, but that was a nightmare since
    TMP_FontAsset
    was missing.
     
  16. Bearsauce

    Bearsauce

    Joined:
    Jan 4, 2019
    Posts:
    26
    I am facing the same issue (I think it is?) in Unity 2020.3.5f1 with TMP 3.0.6 (was unable to try with 3.2.0-pre.3):

    Code (CSharp):
    1. Material 'NotoSansJP-Bold SDF Material' with Shader 'TextMeshPro/Distance Field' doesn't have a float or range property '_CullMode'
    2. UnityEngine.Material:GetFloat (string)
    3. TMPro.TMP_SubMeshUI:UpdateMaterial () (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_SubMeshUI.cs:710)
    4. TMPro.TMP_SubMeshUI:SetMaterialDirty () (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_SubMeshUI.cs:617)
    5. UnityEngine.UI.MaskableGraphic:OnDisable ()
    6. TMPro.TMP_SubMeshUI:OnDisable () (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_SubMeshUI.cs:286)
    My findings:
    • Scene change triggers the problem
    • I can reproduce the issue with 100% consistency in the editor, but in build version the issue doesn't happen
    • I am using I2 Localization asset to handle text localization and switching the font assets/materials
    • For me the issue happens when I switch from English font asset to Japanese before the scene change. The issue does not happen if the game starts with Japanese selected. It also does not happen if I switch from Russian font asset to Japanese. I assume the specific languages are not important, but somehow their respective font assets differ in this.
    • I was unable to try this with version 3.2.0-pre.3 as I got another error (Library\PackageCache\com.unity.textmeshpro@3.2.0-pre.3\Scripts\Editor\TMP_FontAssetEditor.cs(2005,77): error CS1503: Argument 2: cannot convert from 'string' to 'int')
     
  17. Dasp

    Dasp

    Joined:
    Sep 25, 2012
    Posts:
    38
    Looks like we have the same issue in our builds. It happened first time for us. We load Fonts and Materials from Addressables. Haven't found why it happens yet.
    We are also using i2 Localization but we are not changing materials.
    After restarting the game issue got fixed.

    [Update]
    Found source of the issue. At least I think so.
    We are loading fonts and materials from addressables to avoid duplicated and when doing game reset we probably had null material references. So I needed to clean material references when resetting progress in the game. But I'm not 100% sure with this.

    Unity: 2021.3.4
    TMP: 3.2.0-pre.3
    Build Target: iOS
     
    Last edited: Jun 17, 2022
    Brown2Fox likes this.
  18. dmitry-matveev

    dmitry-matveev

    Joined:
    Jul 20, 2022
    Posts:
    2
    bump, it is not fixed yet
     
    Dasp and gelllard like this.
  19. Tyrannicus100BC

    Tyrannicus100BC

    Joined:
    Apr 24, 2015
    Posts:
    5
    bump, also having this issue. Seems to be caused by AssetBundle.UnloadAllAssetBundles(true), which is critical to our project.
     
  20. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Any chance, you can submit a bug report with project / repro scene? This always makes it much faster to reproduce and identify the potential source of the issue.
     
  21. dmitry-matveev

    dmitry-matveev

    Joined:
    Jul 20, 2022
    Posts:
    2
    No repro but I wrote simple hack to remove all errors in Firebase Console and Unity Crash logs:

    private void ReleaseTextMeshPro()
    {
    var objs = GameObject.FindObjectsOfType(typeof(GameObject), true).Cast<GameObject>()
    .Where(o => o.transform.parent == null).ToList();
    var comps = objs.SelectMany(o => o.GetComponentsInChildren<TMP_SubMeshUI>(true)).ToArray();

    Debug.Log("[GameEntryPoint] Found TMP_SubMeshUI : " + comps.Length);

    foreach (TMP_SubMeshUI m in comps)
    {
    if (m == null) continue;
    Debug.Log("[GameEntryPoint] Found " + m.gameObject.GetPath());
    GameObject.DestroyImmediate(m.gameObject);
    }

    }

    And I launch this method in MonoBehaviour.OnApplicationQuit() callback

    PS All prefabs with TMP_SubMeshUI are prefabs loaded from Asset Bundle with TMP Text with TMP_Sprite_Asset (icon in text), each icon adds one additional exception if stays in game during quitting
     
    won-gyu, Menion-Leah and Kevin-Alkemi like this.
  22. Braza

    Braza

    Joined:
    Oct 11, 2013
    Posts:
    136
    upload_2022-9-2_16-38-37.png
    I see TMP instances sitting under a Mask trigger those exception if I start changibg scene.
     
  23. larssonmartin1998

    larssonmartin1998

    Joined:
    Dec 12, 2017
    Posts:
    11
    Hey, I'm having the same issue.

    upload_2022-9-24_16-48-25.png

    Any fixes available for this outside of changing the package yourself?

    I'm on Unity 2021.3.4f1. Running on a M1 MacBook Pro on macOS Monterey 12.6, however, it's also reproducible on my Windows machine.

    This happens when I try to release a Prefab loaded with Addressables. The prefab contains a TMP object with rich text containing a sprite.

    Edit: As discussed above this is easily fixed by adding a null check in TMP_SubMeshUI.UpdateMaterial like so:

    Code (CSharp):
    1. if (m_sharedMaterial.HasProperty(ShaderUtilities.ShaderTag_CullMode))
    2. {
    3.     if (textComponent.fontSharedMaterial != null)
    4.     {
    5.         float cullMode = textComponent.fontSharedMaterial.GetFloat(ShaderUtilities.ShaderTag_CullMode);
    6.         m_sharedMaterial.SetFloat(ShaderUtilities.ShaderTag_CullMode, cullMode);
    7.     }
    8. }
    That will at least solve the runtime error. But it'd be great to know why the shared material is null to begin with.

    I would just edit the package, but I can't really do that since it just reverts any local changes when I change them.
     
    Last edited: Sep 24, 2022
  24. larssonmartin1998

    larssonmartin1998

    Joined:
    Dec 12, 2017
    Posts:
    11
    @Stephan_B Is there as update to this, or some issue tracker I can track to get some info on a potential fix for this?

    It happens for me consistently every time I just disable the gameObject that is owning a TMP_Text component with rich text enabled & contains sprites when that object is a child if an instantiated prefab which was loaded from an Asset Bundle. Same goes if I destroy the root object.

    EDIT: I'm on Unity 2021.3.4f1
     
  25. GustavNinja

    GustavNinja

    Joined:
    Jun 13, 2016
    Posts:
    96
    @Stephan_B
    Before on 2019.4.28f1 I fix this by switching the TMP_SubMeshUI with my own fixed class and it worked and I had been using it until this was fixed. But yesterday I updated the game to 2020.3.38f1 and my replacement scripts works but right after I replace the file, Unity's package manager forcefully rebuilds all packages... Now I'm back with 500~1000 errors a day because of this.

    Code (CSharp):
    1. The package cache was invalidated and rebuilt because the following immutable asset(s) were unexpectedly altered:
    2.   Packages/com.unity.textmeshpro/Scripts/Runtime/TMP_SubMeshUI.cs
    I added the latest preview package but this fix has still not been implemented. Any time limit on this fix?

    *Update*
    I failed to update the file by replacing it so I ended up embedding TMP package so that it becomes a custom package. Which now I can freely change TMP_SubMeshUI and build it with no problem. I will do this for now.
     
    Last edited: Oct 19, 2022
  26. omg_peter

    omg_peter

    Joined:
    Dec 7, 2020
    Posts:
    11
    Would be great to have a fix for this. As it stands it looks like we'll need to fork our own version in order to avoid this issue.
     
  27. shivaprasad_unity

    shivaprasad_unity

    Joined:
    Mar 30, 2021
    Posts:
    19
  28. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I made the recommended change from this thread. This change will be in the next preview release which should be version 3.2.0-pre.4 which should be available within the next 7 - 14 days.
     
  29. GustavNinja

    GustavNinja

    Joined:
    Jun 13, 2016
    Posts:
    96
    Thanks for the changes. When it leaves preview I will update the project.
     
  30. shai_unity622

    shai_unity622

    Joined:
    Aug 1, 2022
    Posts:
    4
    @Stephan_B
    If we don't want to use a preview version but want to fix this issue that crashes the game for a very big portion of our users, how should we proceed?

    Is there a way to modify TMP_SubMeshUI without the changes being lost as it's part of a package?
     
    Menion-Leah and Unifikation like this.
  31. RisingSunStudios

    RisingSunStudios

    Joined:
    May 23, 2018
    Posts:
    34
    I've upgraded to 3.2.0-pre.4 and this bug still exists.
     
  32. wechat_os_Qy0-eaEFbMNNTlspV871un3L0

    wechat_os_Qy0-eaEFbMNNTlspV871un3L0

    Joined:
    Feb 18, 2022
    Posts:
    1
    It worked great, thx
     
  33. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
    Thanks for providing this workaround!
    It works great, without the need of modifying the original TMP package.
     
  34. Avelblood

    Avelblood

    Joined:
    May 5, 2016
    Posts:
    6
    Literally every bug I face is already lying on this forum for years. I'm happy that in this case there is at least some workaround.
     
    Menion-Leah likes this.
  35. vuthang

    vuthang

    Joined:
    Mar 7, 2017
    Posts:
    50
    Hi @Stephan_B I use unity 2022.3.7, TMP 3.0.6, Addressable 1.21.17 and this issue still occurs
     
  36. efelatte

    efelatte

    Joined:
    May 15, 2013
    Posts:
    8
    Still receiving these errors with Unity 2022.3.10, taking up space in our projects Sentry domain.
     
  37. olddisk

    olddisk

    Joined:
    Apr 21, 2014
    Posts:
    1
    Still receiving these errors with Unity 2022.3.3
     
  38. PavelK88

    PavelK88

    Joined:
    Nov 27, 2019
    Posts:
    1
    Hi @Stephan_B I use unity 2022.3.20 and this issue still occurs. You fastly made changes for VisionOS for some people, but totally ignoring A LOT OF PEOPLE with this bug!
     
  39. jonathan_lumos

    jonathan_lumos

    Joined:
    Jan 20, 2022
    Posts:
    4
  40. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    498
    Hi! Sorry I'm new to this issue. Did someone log a bug with the Unity Bug Reporter ?

    Also, have you tried with the latest version of TMP 3.2.0-pre.x ? It's possible the issue has already been fixed. See the beginning of this post for more info on how to import the package in 2023.1 and earlier versions.