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.
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?
if (m_sharedMaterial.HasProperty(ShaderUtilities.ShaderTag_CullMode))
{
if (textComponent.fontSharedMaterial)
{
float cullMode = textComponent.fontSharedMaterial.GetFloat(ShaderUtilities.ShaderTag_CullMode);
m_sharedMaterial.SetFloat(ShaderUtilities.ShaderTag_CullMode, cullMode);
}
}
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?
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.
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.
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.
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
Open Start scene
Press Initialize button then select whatever scene you want to go to.
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
@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.
@Stephan_B Still seeing this too (Crashlytics only):
Non-fatal Exception: java.lang.Exception: NullReferenceException : Object reference not set to an instance of an object.
at TMPro.TMP_SubMeshUI.UpdateMaterial(TMPro.TMP_SubMeshUI)
at TMPro.TMP_SubMeshUI.SetMaterialDirty(TMPro.TMP_SubMeshUI)
at UnityEngine.UI.MaskableGraphic.OnDisable(UnityEngine.UI.MaskableGraphic)
at TMPro.TMP_SubMeshUI.OnDisable(TMPro.TMP_SubMeshUI)
Object reference not set to an instance of an object
TMPro.TMP_SubMeshUI.UpdateMaterial () (at <00000000000000000000000000000000>.0)
TMPro.TMP_SubMeshUI.SetMaterialDirty () (at <00000000000000000000000000000000>.0)
UnityEngine.UI.MaskableGraphic.OnDisable () (at <00000000000000000000000000000000>.0)
TMPro.TMP_SubMeshUI.OnDisable () (at <00000000000000000000000000000000>.0)
Faced same issue… just kinda cropped up. I updated to 3.2.0 and it still persists:
NullReferenceException: Object reference not set to an instance of an object
TMPro.TMP_SubMeshUI.UpdateMaterial () (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.3/Scripts/Runtime/TMP_SubMeshUI.cs:710)
TMPro.TMP_SubMeshUI.SetMaterialDirty () (at Library/PackageCache/com.unity.textmeshpro@3.2.0-pre.3/Scripts/Runtime/TMP_SubMeshUI.cs:617)
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.
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):
Material 'NotoSansJP-Bold SDF Material' with Shader 'TextMeshPro/Distance Field' doesn't have a float or range property '_CullMode'
UnityEngine.Material:GetFloat (string)
TMPro.TMP_SubMeshUI:UpdateMaterial () (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_SubMeshUI.cs:710)
TMPro.TMP_SubMeshUI:SetMaterialDirty () (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_SubMeshUI.cs:617)
UnityEngine.UI.MaskableGraphic:OnDisable ()
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’)
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.
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.