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

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.

1 Like

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.

The same issue on Unity 2019.4.10f1 with TextMeshPro 2.1.3

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.
UnityEngine.Object.get_name () (at <ee47be73f7ef409ca5e5ce4b121745b7>:0)
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)
TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+UnicodeChar[] unicodeChars) (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMPro_UGUI_Private.cs:1383)
TMPro.TMP_Text.ParseInputText () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMP_Text.cs:1892)
TMPro.TextMeshProUGUI.OnPreRenderCanvas () (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TMPro_UGUI_Private.cs:1622)
TMPro.TextMeshProUGUI.Rebuild (UnityEngine.UI.CanvasUpdate update) (at Library/PackageCache/com.unity.textmeshpro@2.1.3/Scripts/Runtime/TextMeshProUGUI.cs:224)
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)
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)

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.

After reimporting the project I couldn’t reproduce the bug :smile:

1 Like

im having the same problem

Any solutions? I’m having the issue on Unity version 2021.3.8f1

1 Like

Happening with 2021.3.10 as well

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?).

2 Likes

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.

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

Same issue with Unity 2022.2.9.

1 Like

Exact same issue. Searching online for help, but there is none to be found.

2 Likes

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.

4 Likes

Same issue. (2021.3.22f1) It happened after edited Prefab’s TextMeshPro-Text in Prefab mode.
I restarted my editor, and solved it.

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.

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.

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

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.

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.