Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro Null Ref when trying to use/create TextMeshPro Text

Discussion in 'UGUI & TextMesh Pro' started by keenanwoodall, Nov 28, 2017.

  1. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    597
    I've done a fresh import of TextMeshPro into Unity 2017.2.0f3

    If I create a new TextMeshPro Text object via the scene's right-click context menu it throws two errors:
    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. TMPro.TMP_Settings.get_defaultFontAsset () (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    4. TMPro.TextMeshProUGUI.LoadFontAsset () (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    5. TMPro.TextMeshProUGUI.OnValidate () (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    6. UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
    7.  
    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. TMPro.TMP_Settings.get_defaultFontAsset () (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    4. TMPro.TextMeshProUGUI.LoadFontAsset () (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    5. TMPro.TextMeshProUGUI.Awake () (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    6. UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
    7.  

    The component in the inspector uses a scriptable object icon instead of the tmp icon.
    upload_2017-11-28_11-31-25.png

    If I type in the text input area I get a null ref every time I press a key and the letters I type don't show in the editor/the text isn't drawn.
    upload_2017-11-28_11-33-31.png

    This is the error I get whenever I type in the text input box:

    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. TMPro.TMP_Settings.get_defaultFontAsset () (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    4. TMPro.TextMeshProUGUI.LoadFontAsset () (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    5. TMPro.TextMeshProUGUI.OnValidate () (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    6. UnityEditor.SerializedObject:ApplyModifiedProperties(SerializedObject)
    7. TMPro.EditorUtilities.TMP_UiEditorPanel:OnInspectorGUI()
    8. UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
    9.  
    Finally, when I tried to move an anchor I got this error:

    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. TMPro.MaterialReference..ctor (System.Int32 index, TMPro.TMP_FontAsset fontAsset, TMPro.TMP_SpriteAsset spriteAsset, UnityEngine.Material material, System.Single padding) (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    4. TMPro.TextMeshProUGUI.SetArraySizes (System.Int32[] chars) (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    5. TMPro.TMP_Text.ParseInputText () (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    6. TMPro.TMP_Text.GetPreferredWidth () (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    7. TMPro.TMP_Text.get_preferredWidth () (at <e10d0e6c7ce84ef8a13b4a8a6c7169f5>:0)
    8. UnityEditor.Events.LayoutPropertiesPreview.<OnPreviewGUI>m__2 (UnityEngine.UI.ILayoutElement e) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEditor.UI/UI/LayoutPropertiesPreview.cs:96)
    9. UnityEngine.UI.LayoutUtility.GetLayoutProperty (UnityEngine.RectTransform rect, System.Func`2[T,TResult] property, System.Single defaultValue, UnityEngine.UI.ILayoutElement& source) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Layout/LayoutUtility.cs:86)
    10. UnityEditor.Events.LayoutPropertiesPreview.OnPreviewGUI (UnityEngine.Rect r, UnityEngine.GUIStyle background) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEditor.UI/UI/LayoutPropertiesPreview.cs:96)
    11. UnityEditor.ObjectPreview.OnInteractivePreviewGUI (UnityEngine.Rect r, UnityEngine.GUIStyle background) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:113)
    12. UnityEditor.ObjectPreview.DrawPreview (UnityEditor.IPreviewable defaultPreview, UnityEngine.Rect previewArea, UnityEngine.Object[] targets) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:223)
    13. UnityEditor.ObjectPreview.DrawPreview (UnityEngine.Rect previewArea) (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:127)
    14. UnityEditor.InspectorWindow.DrawPreviewAndLabels () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:758)
    15. UnityEditor.InspectorWindow.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:398)
    16. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <9c9f068c46c64ffd91fda7af157b4d15>:0)
    17. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    18. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <9c9f068c46c64ffd91fda7af157b4d15>:0)
    19. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <9c9f068c46c64ffd91fda7af157b4d15>:0)
    20. UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:285)
    21. UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:278)
    22. UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:251)
    23. UnityEditor.DockArea.OldOnGUI () (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:383)
    24. UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt) (at C:/buildslave/unity/build/Runtime/UIElements/Managed/IMGUIContainer.cs:143)
    25. UnityEngine.Experimental.UIElements.IMGUIContainer.HandleEvent (UnityEngine.Experimental.UIElements.EventBase evt) (at C:/buildslave/unity/build/Runtime/UIElements/Managed/IMGUIContainer.cs:213)
    26. UnityEngine.Experimental.UIElements.IMGUIContainer.DoRepaint (UnityEngine.IStylePainter painter) (at C:/buildslave/unity/build/Runtime/UIElements/Managed/IMGUIContainer.cs:50)
    27. UnityEngine.Experimental.UIElements.Panel.PaintSubTree (UnityEngine.Event e, UnityEngine.Experimental.UIElements.VisualElement root, UnityEngine.Matrix4x4 offset, UnityEngine.Rect currentGlobalClip) (at C:/buildslave/unity/build/Runtime/UIElements/Managed/Panel.cs:447)
    28. UnityEngine.Experimental.UIElements.Panel.PaintSubTree (UnityEngine.Event e, UnityEngine.Experimental.UIElements.VisualElement root, UnityEngine.Matrix4x4 offset, UnityEngine.Rect currentGlobalClip) (at C:/buildslave/unity/build/Runtime/UIElements/Managed/Panel.cs:457)
    29. UnityEngine.Experimental.UIElements.Panel.Repaint (UnityEngine.Event e) (at C:/buildslave/unity/build/Runtime/UIElements/Managed/Panel.cs:474)
    30. UnityEngine.Experimental.UIElements.UIElementsUtility.DoDispatch (UnityEngine.Experimental.UIElements.BaseVisualElementPanel panel) (at C:/buildslave/unity/build/Runtime/UIElements/Managed/UIElementsUtility.cs:192)
    31. UnityEngine.Experimental.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at C:/buildslave/unity/build/Runtime/UIElements/Managed/UIElementsUtility.cs:72)
    32. UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at C:/buildslave/unity/build/Runtime/IMGUI/Managed/GUIUtility.cs:175)
    33.  
     

    Attached Files:

    Last edited: Nov 28, 2017
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Did you import an updated version of TextMesh Pro into an existing project? If so, and as per the release and upgrade notes, when upgrading to a new version of TMP you have to remove the previous package first by deleting the "TextMesh Pro" folder before importing the new one. Be sure to always backup your project first and any files or assets you may have saved inside the "TextMesh Pro" folder hierarchy.

    Next, make sure that you have a font asset assigned as Default in the TMP Settings file.

    Try the same process in a new Empty project.
     
  3. keenanwoodall

    keenanwoodall

    Joined:
    May 30, 2014
    Posts:
    597
    Thanks. I think it's fixed now.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    BTW: There is a new release of TMP available for Unity 5.5 - 2017.3. Links to download those directly is in the top sticky post in this forum. The releases should be available on the Asset Store next week or something.
     
  5. lemfn64

    lemfn64

    Joined:
    Mar 14, 2017
    Posts:
    2
    OMG Thanks so much. I spent an hour on this issue and your solution using the file on the link not the asset store one plus some reimports and closing and opening unity did it. I was about to give up and was typing here for help when the errors just vanished as i opened unity again. Thank you!!!!
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I am sorry that you ran into issues with getting the correct version from the Asset Store and glad you got everything working.
     
  7. Buka

    Buka

    Joined:
    Feb 22, 2013
    Posts:
    48
    Hi, I have this problem with Unity version as well, just downloaded TextMeshPro from store, version
    TextMeshPro-2017.3-1.0.56
    I have Unity version 2017.3.0p3
    Dll is not recognized, things are working in editor but if I want to access the text from the code I can't. Tried to remove / redownload textmeshpro but none worked. What can I do, update to latest Unity (don't want to mess things up and force everyone to update without reason but if we have to do so, then ok I guess) or there is another catch? @UnityTechnologies
    Thanks!!!
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Are you getting errors when running any / all of the examples included with TextMesh Pro?

    Are you using scripts that used to work or are these new scripts where you are trying to access these text component? If these are new scripts, then keep in mind there are two TexMesh Pro components. There is one designed to replace the old TextMesh and work with the Mesh Renderer and the other designed to replace UI.Text and works with the CanvasRenderer. As such if your object has one of these text components attached while you are trying to access the other type via your script, you will get null references.

    See the following post on page 2 here.
     
  9. Buka

    Buka

    Joined:
    Feb 22, 2013
    Posts:
    48
    Thanks for answer but once I updated Unity to latest version everything is working properly so no worries with TextMeshPro. The problem I was facing is that TMPro namespace wasn't registered by Unity version I had, once updated everything worked like a charm :) Cheers!!!
     
    Stephan_B likes this.