Search Issue Tracker

Won't Fix



Found in [Package]



Issue ID




NullReferenceException error thrown when creating or selecting Text in Hierarchy with TMP Essentials imported

Package: TextMeshPro


How to reproduce:
1. Open up any project
2. In the Hierarchy right click and create "UI > Text - TextMeshPro"
3. Import TextMeshPro Essentials when prompted
4. Observe Console
5. Unselect the Hierarchy component, then select "Text (TMP)" again
6. Observe Console

Expected result: Console displays TextMeshPro Essentials imported
Actual result: Console displays [] have been imported and "NullReferenceException: Object reference not set to an instance of an object" error printed

Reproducible with: 2023.1.0a10, 2023.1.0a11 (3.0.6 TMP)
Not reproducible with: 2020.3.40f1, 2021.3.10f1, 2022.1.17f1, 2022.2.0b8, 2023.1.0a9 (3.0.6)

Start of error message:
[] have been imported.
UnityEngine.Debug:Log (object)
TMPro.TMP_PackageResourceImporter:ImportCallback (string) (at C:/t/My project (174)/Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMP_PackageResourceImporter.cs:107)
UnityEditor.AssetDatabase:Internal_CallImportPackageCompleted (string)

NullReferenceException: Object reference not set to an instance of an object
TMPro.MaterialReference..ctor (System.Int32 index, TMPro.TMP_FontAsset fontAsset, TMPro.TMP_SpriteAsset spriteAsset, UnityEngine.Material material, System.Single padding) (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/MaterialReferenceManager.cs:525)

  1. Resolution Note:

    There are no fixes planned for this Bug

Comments (2)

  1. Bunzaga

    Sep 11, 2023 01:12

    Closing and reopening Unity seemed to resolve this for me (2023.3.18f1). The steps in the original post is the exact thing I ran into. Just as a note, you have to not have TMP imported ahead of time, but that may seem obvious.

  2. chrismarch

    Mar 29, 2023 00:13

    We're seeing this frequently in our iOS and Android builds. Here are some more recent version numbers and a callstack:

    Unity 2020.3.45f1
    TMPro Version 3.2.0-pre.4 - December 16, 2022
    iOS 16.3

    "TMPro.MaterialReference..ctor (System.Int32 index, TMPro.TMP_FontAsset fontAsset, TMPro.TMP_SpriteAsset spriteAsset, UnityEngine.Material material, System.Single padding)
    TMPro.TextMeshProUGUI.SetArraySizes (TMPro.TMP_Text+TextProcessingElement[] textProcessingArray)
    TMPro.TMP_Text.GetPreferredWidth ()
    TMPro.TMP_Text.get_preferredWidth ()
    System.Func`2[T,TResult].Invoke (T arg)
    UnityEngine.UI.LayoutUtility.GetLayoutProperty (UnityEngine.RectTransform rect, System.Func`2[T,TResult] property, System.Single defaultValue, UnityEngine.UI.ILayoutElement& source)
    UnityEngine.UI.LayoutUtility.GetPreferredWidth (UnityEngine.RectTransform rect)
    UnityEngine.UI.HorizontalOrVerticalLayoutGroup.GetChildSizes (UnityEngine.RectTransform child, System.Int32 axis, System.Boolean controlSize, System.Boolean childForceExpand, System.Single& min, System.Single& preferred, System.Single& flexible)
    UnityEngine.UI.HorizontalOrVerticalLayoutGroup.CalcAlongAxis (System.Int32 axis, System.Boolean isVertical)
    UnityEngine.Events.UnityAction`1[T0].Invoke (T0 arg0)
    UnityEngine.UI.LayoutRebuilder.PerformLayoutCalculation (UnityEngine.RectTransform rect, UnityEngine.Events.UnityAction`1[T0] action)
    UnityEngine.UI.LayoutRebuilder.Rebuild (UnityEngine.UI.CanvasUpdate executing)
    UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate ()
    UnityEngine.Canvas+WillRenderCanvases.Invoke ()
    UnityEngine.UI.ScrollRect.SetNormalizedPosition (System.Single value, System.Int32 axis)
    UnityEngine.UI.ScrollRect.set_normalizedPosition (UnityEngine.Vector2 value)
    <cusom monobehavior>.Awake ()

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.