Search Unity

TextMeshPro Missing Reference Exception OnPrefabInstanceUpdate

Discussion in 'UGUI & TextMesh Pro' started by Rafael_CS, Jan 8, 2020.

  1. Rafael_CS

    Rafael_CS

    Joined:
    Sep 16, 2013
    Posts:
    162
    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)"

    Code (CSharp):
    1. /// <summary>
    2.         void OnPrefabInstanceUpdate(GameObject go)
    3.         {
    4.             if (go == this.gameObject) // this line will return null on asset reimport because this == null
    5.             {
    6.                 TMP_SubMeshUI[] subTextObjects = GetComponentsInChildren<TMP_SubMeshUI>();
    7.                 if (subTextObjects.Length > 0)
    8.                 {
    9.                     for (int i = 0; i < subTextObjects.Length; i++)
    10.                         m_subTextObjects[i + 1] = subTextObjects[i];
    11.                 }
    12.             }
    13.         }
    upload_2020-1-7_23-23-11.png

    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<CanvasRenderer>();

    Code (CSharp):
    1. public override void Cull(Rect clipRect, bool validRect)
    2.         {
    3.             //Debug.Log("***** Cull (" + clipRect + ", " + validRect + ")   Cull: " + m_canvasRenderer.cull + " *****");
    4.  
    5.             if (validRect)
    6.             {
    7.                 m_canvasRenderer.cull = false; //This line, sometimes contains m_canvasRenderer == null in editor
    8.                 CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(this);
    9.                 return;
    10.             }
    11.  
    12.             base.Cull(clipRect, validRect);
    13.         }
    upload_2020-1-7_23-57-48.png
     
    Last edited: Jan 8, 2020
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    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 :)
     
    Rafael_CS likes this.