TMP nullreference in build

We’re running into a myriad of nullreferences in TextMeshPro, but only in a build. I’ve checked and made sure all fonts and materials are in the resources folder, but otherwise i’m not quite sure how to debug this issue. I’ve seen some corrupt SubTextObjects before, they would remain visible in the prefab in editor time. But those are all deleted.

It only happens in a build, which uses assetbundles. In editor with assetbundles the issue does not occur. The UI is being spawned from a prefab, but there are no issues there (its all visible). It doesnt occur with all text, and it all still seems to be properly rendered.

We’re building with Unity 2017.1.2, currently waiting on a few issues to be fixed before we can update to 2017.3.

NullReferenceException: Object reference not set to an instance of an object
  at TMPro.TMP_SubMeshUI.UpdateMaterial () [0x00000] in <filename unknown>:0
  at TMPro.TMP_SubMeshUI.SetMaterialDirty () [0x00000] in <filename unknown>:0
  at TMPro.TMP_SubMeshUI.RecalculateMasking () [0x00000] in <filename unknown>:0
  at TMPro.TMP_SubMeshUI.OnEnable () [0x00000] in <filename unknown>:0
UnityEngine.GameObject:Internal_AddComponentWithType(Type)
UnityEngine.GameObject:AddComponent(Type)
UnityEngine.GameObject:AddComponent()
TMPro.TMP_SubMeshUI:AddSubTextObject(TextMeshProUGUI, MaterialReference)
TMPro.TextMeshProUGUI:SetArraySizes(Int32[])
TMPro.TMP_Text:parseInputText()
TMPro.TextMeshProUGUI:OnPreRenderCanvas()
TMPro.TextMeshProUGUI:Rebuild(CanvasUpdate)
UnityEngine.UI.CanvasUpdateRegistry:performUpdate()
UnityEngine.Canvas:SendWillRenderCanvases()


NullReferenceException: Object reference not set to an instance of an object
  at TMPro.TMP_SubMeshUI.UpdateMaterial () [0x00000] in <filename unknown>:0
  at TMPro.TMP_SubMeshUI.SetMaterialDirty () [0x00000] in <filename unknown>:0
  at UnityEngine.UI.MaskableGraphic.OnCanvasHierarchyChanged () [0x00000] in <filename unknown>:0
UnityEngine.Object:smile:estroy(Object, Single)
UnityEngine.Object:smile:estroy(Object)
LoadingScreenManager:CloseMenu()
LoadingScreenBase:doneLoading()
LoadingScreenBase:Update()

NullReferenceException: Object reference not set to an instance of an object
  at TMPro.TMP_SubMeshUI.UpdateMaterial () [0x00000] in <filename unknown>:0
  at TMPro.TMP_SubMeshUI.SetMaterialDirty () [0x00000] in <filename unknown>:0
  at UnityEngine.UI.MaskableGraphic.OnDisable () [0x00000] in <filename unknown>:0
  at TMPro.TMP_SubMeshUI.OnDisable () [0x00000] in <filename unknown>:0

Most likely the Asset Bundles are losing their reference to either the material, font atlas texture and possibly shader.

When the bundle is loaded, make sure these resources are assigned properly to the font asset.

We keep running into this issue, even when we dont use assetbundles at all.

NullReferenceException: Object reference not set to an instance of an object
  at TMPro.TMP_SubMeshUI.UpdateMaterial () [0x00000] in <filename unknown>:0
  at TMPro.TMP_SubMeshUI.SetMaterialDirty () [0x00000] in <filename unknown>:0
  at UnityEngine.UI.MaskableGraphic.OnDisable () [0x0000f] in C:\buildslave\unity\build\Extensions\guisystem\UnityEngine.UI\UI\Core\MaskableGraphic.cs:133
  at TMPro.TMP_SubMeshUI.OnDisable () [0x00000] in <filename unknown>:0

We were spying into the DLL for a bit, maybe its the fact that components are added/getted in an OnDisable?

Are you able to reliably reproduce this? If so please submit a bug report with the case #.

https://fogbugz.unity3d.com/default.asp?1027955_hijpl58sn1u01jrk

Ish… It seems like the issue there is that the shaders got in a different bundle.

I just tried not spawning our whole mainmenu ui prefab but just one prefab with a label in there. That did work, ill comb through the prefab more tomorrow.

Alright, we’ve finally found the issue. And it’s totally unrelated to TextMeshPro, and completely our fault.

We are very performance conscious, and therefore we modified the UnityEngine DLL to skip RequireComponents checks. This sped up Destroying objects massively (500ms per player dying), and didnt cause any issues at that moment. However the TMP_SubMeshUI correctly relies on RequireComponent to add this CanvasRenderer.

Apologies!

No apologies necessary. Glad you have identified the source of the behavior :slight_smile: