Search Unity

TextMesh Pro Getting error message MissingReferenceException: The object of type 'Material' has been destroyed

Discussion in 'UGUI & TextMesh Pro' started by sushanta1991, Dec 26, 2019.

  1. sushanta1991

    sushanta1991

    Joined:
    Apr 3, 2011
    Posts:
    305
    MissingReferenceException: The object of type 'Material' has been destroyed but you are still trying to access it.
    Your script should either check if it is null or you should not destroy the object.
    TMPro.TextMeshProUGUI.GenerateTextMesh () (at Library/PackageCache/com.unity.textmeshpro@1.4.1/Scripts/Runtime/TMPro_UGUI_Private.cs:2098)
    TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at Library/PackageCache/com.unity.textmeshpro@1.4.1/Scripts/Runtime/TMPro_UGUI_Private.cs:1657)
    TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro@1.4.1/Scripts/Runtime/TextMeshProUGUI.cs:209)
    UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:198)
    UnityEngine.UI.ScrollRect:LateUpdate()


    Hi, I am using Unity2018.4.4

    I have a (Text (TMP) game object) with this text written below

    • Allows after market stereo to be installed in factory location

    The above text creates a child with TMP SubMeshUI [LiberationSans SDF Material] component. Which throughs the error "'Material' has been destroyed".

    The error comes after I close the play mode.
     
    hyperrrrrea7 likes this.
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Please test with the latest preview release of TMP which is version 1.5.0-preview.3 and let me know if the issue persists.
     
  3. Tymianek

    Tymianek

    Joined:
    May 16, 2015
    Posts:
    97
    The same issue on Unity 2019.4.10f1 with TextMeshPro 2.1.3

    Code (CSharp):
    1. MissingReferenceException: The object of type 'Material' has been destroyed but you are still trying to access it.
    2. Your script should either check if it is null or you should not destroy the object.
    3. UnityEngine.Object.get_name () (at <ee47be73f7ef409ca5e5ce4b121745b7>:0)
    4. TMPro.TMP_SubMeshUI.AddSubTextObject (TMPro.TextMeshProUGUI textComponent, TMPro.MaterialReference materialReference) (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMP_SubMeshUI.cs:214)
    5. TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] unicodeChars) (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMPro_UGUI_Private.cs:1383)
    6. TMPro.TMP_Text.ParseInputText () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMP_Text.cs:1892)
    7. TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMPro_UGUI_Private.cs:1622)
    8. TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TextMeshProUGUI.cs:224)
    9. UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/Program Files/Unity/Hub/Editor/2019.4.10f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/CanvasUpdateRegistry.cs:210)
    10. UnityEngine.UI.ScrollRect:LateUpdate() (at C:/Program Files/Unity/Hub/Editor/2019.4.10f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/UI/Core/ScrollRect.cs:805)
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Can you submit a bug report with project and steps for me to take a closer look at?

    If you do submit a bug report please provide me with the Case # once you get it from Unity via email.
     
  5. Tymianek

    Tymianek

    Joined:
    May 16, 2015
    Posts:
    97
    After reimporting the project I couldn't reproduce the bug :D
     
    navywill likes this.
  6. soulsinister

    soulsinister

    Joined:
    Aug 12, 2022
    Posts:
    1
    im having the same problem
     
  7. af_unity994

    af_unity994

    Joined:
    Aug 17, 2022
    Posts:
    2
    Any solutions? I'm having the issue on Unity version 2021.3.8f1
     
    hyperrrrrea7 likes this.
  8. Coderious

    Coderious

    Joined:
    Mar 28, 2020
    Posts:
    26
    Happening with 2021.3.10 as well
     
  9. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    Got it on 2022.1.10f1 with TMP 3.0.6.

    I'm defining a prefab (variant) with TMP text on it, which auto-generates TMP SubMeshUI [LiberationSans SDF Material] child (although I'm using a different font), and the prefab instance sometimes creates its own child too, sometimes has no children at all (not sure how it's possible, it manages to bypass "prefab permissions" and delete/replace a prefab child?).
     
    hyperrrrrea7 and kdwojtas like this.
  10. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    322
    Happens for me as well on 2021.3.6f1 LTS and TMP 3.0.6.
    It happens only with a "Bitmap Custom Atlas" shader that a submesh is created and it gets deleted after exiting play mode. If I deactivate the TextMeshPro object then in the editor and reactivate it, the submesh gets created anew.
     
  11. kdwojtas

    kdwojtas

    Joined:
    Jan 20, 2018
    Posts:
    1
    Same issue. I also have Bitmap custom atlas. Not all ascii characters are mapped in the bitmap and I am changing text via code. Using 2021.3.18f1 LTS and TMP 3.0.6
     
  12. CasimmVancouver

    CasimmVancouver

    Joined:
    May 28, 2019
    Posts:
    3
    Same issue with Unity 2022.2.9.
     
    datablob likes this.
  13. Skuttle-Studios

    Skuttle-Studios

    Joined:
    Feb 25, 2023
    Posts:
    1
    Exact same issue. Searching online for help, but there is none to be found.
     
    hyperrrrrea7 and datablob like this.
  14. datablob

    datablob

    Joined:
    Dec 19, 2020
    Posts:
    9
    Happens for me quite frequently in Unity 2021.3.20f1 using TextMeshPro 3.0.6, seems to have worsened with the latest Unity LTS upgrade.

    Edit:

    Resetting the Default Font Asset in Project Settings back to LiberationSans SDF fixed these errors for me.
     
    Last edited: Mar 13, 2023
  15. HammerImpact

    HammerImpact

    Joined:
    Nov 5, 2016
    Posts:
    1
    Same issue. (2021.3.22f1) It happened after edited Prefab's TextMeshPro-Text in Prefab mode.
    I restarted my editor, and solved it.
     
    Last edited: May 10, 2023
  16. mat108

    mat108

    Joined:
    Aug 24, 2018
    Posts:
    132
    Anyone know how to fix this mess? Appeared out of nowhere in Unity 2020.3.41f. using TMP 3.0.6
    Unity truly is falling apart at an incredible pace.
     
  17. Tymac

    Tymac

    Joined:
    Nov 12, 2015
    Posts:
    10
    Resetting the editor isn't going to solve this issue because the vast majority of people who are reporting this error (like myself) see it constantly. I see it every time I exit play mode. I tried Datablob's suggestion of (Resetting the Default Font Asset) and it seems to have solved it for now.
     
  18. yoloandoyolo

    yoloandoyolo

    Joined:
    Jul 1, 2022
    Posts:
    7
    Getting the same issue and the aforementioned fixes do not help. This happens when using prefabs and prefabs variants that have a TMP child with a custom font. Breaks builds unless we set the standard font
     
  19. datablob

    datablob

    Joined:
    Dec 19, 2020
    Posts:
    9
    I was using a bitmap font and noticed that the submesh object was being created due to spaces in the string. I'm assuming the spaces are rendered by the fallback font.

    Apparently my bitmap font is lacking a space character? This only happens with the raster hinted version of the font asset, SDF is curiously unaffected, neither show a char/glyph for space when I search for them in the font asset inspector.
     
  20. Ryalin

    Ryalin

    Joined:
    Apr 25, 2019
    Posts:
    8
    Unity Version: 2021.3.30f1 LTS,
    TMPro version: 3.0.6

    Anyone had any luck with this? Literally doing my head in.
    It lets me set my fonts to LiberationSans SDF, but using my custom fonts results in the 'The object of type 'Material' has been destroyed but you are still trying to access it' errors which occur at line 1403 of the TMPro_UGUI_Private.cs > line 215 of the TMP_SubMeshUI.cs.
    These errors only occur after closing the game from the game viewer.
    I am also able to actually see my fonts displayed just fine.

    I might add that this started happening when upgrading from 2019 to 2021.3.30f1 version of unity, I didn't get these errors in the 2019 version I was using.
    I can also actually use all my custom fonts just fine, I just want to prevent the error spam after running in the Game Viewer.
     
  21. JordiRM

    JordiRM

    Joined:
    Jan 7, 2015
    Posts:
    2
    Like datablob says, the problem seems to be the space character. i have created a font ttf only with characters A to Z and configured the tmp font with customs characters. Works fine as long as you don't use any space, otherwise, throughs the error when quitting.
    If i configure the tmp font with Extended ascii (in my case), even if there are missing characters, the problem is gone.
     
  22. nicloay

    nicloay

    Joined:
    Jul 11, 2012
    Posts:
    540
    In my case, it mentioned destroyed material, so disabling this option in the project settings did the trick for me upload_2023-11-15_21-2-8.png
     
  23. whdgns4433

    whdgns4433

    Joined:
    Apr 14, 2023
    Posts:
    1
    YES THIS SOLVED MY ISSUE! Thank you so much!!!