Search Unity

TextMesh Pro FindIntersectingLinks Null ref exception

Discussion in 'UGUI & TextMesh Pro' started by astromedia-only, Sep 8, 2019.

  1. astromedia-only

    astromedia-only

    Joined:
    May 13, 2014
    Posts:
    25
    Hi,
    im trying to handle click on link inside text and when i do click it gives me this:

    NullReferenceException: Object reference not set to an instance of an object
    TMPro.TMP_TextUtilities.FindIntersectingLink (TMPro.TMP_Text text, UnityEngine.Vector3 position, UnityEngine.Camera camera) (at Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Runtime/TMP_TextUtilities.cs:1348)
    UIChatLineLinkHandler.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Assets/UIChatLineLinkHandler.cs:42)
    UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/Program Files/Unity/Hub/Editor/2019.3.0a10/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:50)
    UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/Program Files/Unity/Hub/Editor/2019.3.0a10/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/ExecuteEvents.cs:261)
    UnityEngine.EventSystems.EventSystem:Update()

    Problem is with:
    Transform rectTransform = text.transform;
    - transform was not found but im not sure why.

    I have tryed blank scene, just created TMP Text, attached script to it and used this inside:
    Code (CSharp):
    1. public void OnPointerClick(PointerEventData eventData)
    2. {
    3.         // Check if mouse intersects with any links.
    4.         int linkIndex = TMP_TextUtilities.FindIntersectingLink(m_TextMeshPro, Input.mousePosition, m_Camera);
    5. }
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Both TMP text components use a RectTransform so if you need a reference to it, you should be using GetComponent<RectTranform> or the TMP_Text.rectTransform property.
     
  3. astromedia-only

    astromedia-only

    Joined:
    May 13, 2014
    Posts:
    25
    Thx for response. Im kinda confused tho, i dont need it - that function (FindIntersectingLink) does and it is inside TMPro code if i see it correctly ... i have actually tryed to change that to what you are suggesting but it does not seemed to help ... its confusing because why would that object not had recttransform/transform? ... every object inside canvas hierarchy does, i have even checked and it is there ... maybe im doing something wrong or there is bug in TMPro or some combination with version of unity ... it could be my fault but its throwing that error from TMPro code ... i was hoping you can clear for me this confusion :)

    Are you sure this functionality (clickable links) works in Unity 2019.3.0a10 with TMPro 2.0.1 from package manager?

    PS: Also it seems there are no examples included in that package manager version, i had to google pretty hard to get how those links should work with hovering and clicking ... and i was originaly trying to use TMPro forum directly before asking here but it sayed to me registration was closed without giving reason - maybe it will be nice to add there some notice considering link from asset store page is leading there ... but thats just sidenote :)
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    No reports of any potential issues with the above functionality (thus far).

    Take a look at example 12 and 12a included in the TMP Examples & Extras if you have not already done so. Those two examples show potential ways to interact with the text. Example 12 - Link Example uses those functions specifically.
     
  5. astromedia-only

    astromedia-only

    Joined:
    May 13, 2014
    Posts:
    25
    Thats the code from the example i have found somewhere on github (it was nr 12 if i remember correctly) ... as i mentioned above examples does not seems to be included sadly in package manager version of TMPro ... can be examples downloaded somewhere separatedly (without TMPro it self) or i have to import it into new project to take closer look? importing TMPro from asset store into project where is package manager version will pobably not be good idea i suppose.
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Those examples are included with the TMP package. You have to import the TMP Examples & Extras using the Window - TextMesh Pro menu option as seen below.

    upload_2019-9-8_15-5-7.png
     
  7. astromedia-only

    astromedia-only

    Joined:
    May 13, 2014
    Posts:
    25
    Oh, thanks ... it was well hidden i see :) ... thats huge help, example is working properly .. im still confused why my attempt did not worked but i will just copy everything that example is using and strip it down slowly to what i need so i should by ok from now on ... thx again