TextMeshPro Missing Reference Exception OnPrefabInstanceUpdate

Hello @Stephan_B

BUG 1

I found a bug related to method OnPrefabInstanceUpdate inside TMPro_UGUI_Private when asset was reimported and object was detroyed because of this process(unity 2019.3.0f1).

In code below the line “if (go == this.gameObject)” will return null because the “this” is null.
To fix the problem you should change it to “if (this != null && go == this.gameObject)

/// <summary>
        void OnPrefabInstanceUpdate(GameObject go)
        {
            if (go == this.gameObject) // this line will return null on asset reimport because this == null
            {
                TMP_SubMeshUI[] subTextObjects = GetComponentsInChildren<TMP_SubMeshUI>();
                if (subTextObjects.Length > 0)
                {
                    for (int i = 0; i < subTextObjects.Length; i++)
                        m_subTextObjects[i + 1] = subTextObjects[i];
                }
            }
        }

BUG 2

Another bug is related to TextMeshProUGUI line 370.

Sometimes this method was called before m_canvasRenderer != null. to fix the problem we can change m_canvasRenderer to property canvasRenderer or check
if (m_canvasRenderer == null) m_canvasRenderer = GetComponent();

public override void Cull(Rect clipRect, bool validRect)
        {
            //Debug.Log("***** Cull (" + clipRect + ", " + validRect + ")   Cull: " + m_canvasRenderer.cull + " *****");

            if (validRect)
            {
                m_canvasRenderer.cull = false; //This line, sometimes contains m_canvasRenderer == null in editor
                CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(this);
                return;
            }

            base.Cull(clipRect, validRect);
        }

I fixed the above issue a few days ago which appears to be resulting from some change in Unity 2019.3.

I’ll take a closer look at #2.

Thank you for the detailed post :slight_smile:

1 Like