Search Unity

TextMesh Pro Hyperlink did not work as expected

Discussion in 'UGUI & TextMesh Pro' started by ConfusedCactus, Mar 11, 2019.

  1. ConfusedCactus

    ConfusedCactus

    Joined:
    Jul 3, 2018
    Posts:
    19
    Hello all,

    Newbie here. I am using Unity2018.3.5.f1. I was following some great tutorials on creating hyperlinks in textmeshpro, like the one here: https://deltadreamgames.com/unity-tmp-hyperlinks/

    Everything worked as expected, but I ran into an issue, as you can see in the gif I attached, the link only worked when I clicked the first bits of the text, but when I hover to other parts it does not work, as the color does not change to blue :( I think the rectangle outside the words with a hyperlink is too small, so when the mouse hovered on it, it only work on the first bits.

    The script I used is directly from the above-mentioned site (you can find the full script here: https://gitlab.com/jonnohopkins/tmp-hyperlinks/blob/master/Assets/OpenHyperlinks.cs), I think the following bits might be what is causing this behaviour.

    Code (CSharp):
    1.  protected virtual void Awake()
    2.     {
    3.         pTextMeshPro = GetComponent<TextMeshProUGUI>();
    4.  
    5.     }
    6.  
    7.  void LateUpdate()
    8.     {
    9.         // is the cursor in the correct region (above the text area) and furthermore, in the link region?
    10.         var isHoveringOver = TMP_TextUtilities.IsIntersectingRectTransform(pTextMeshPro.rectTransform, Input.mousePosition, pCamera);
    11.  
    12. public void OnPointerClick(PointerEventData eventData)
    13.     {
    14.      
    15.         int linkIndex = TMP_TextUtilities.FindIntersectingLink(pTextMeshPro, Input.mousePosition, pCamera);
    16.         if (linkIndex != -1)
    17.         { // was a link clicked?
    18.             TMP_LinkInfo linkInfo = pTextMeshPro.textInfo.linkInfo[linkIndex];
    19.          
    20.         }
    21.     }
    I guess it is related to either of the functions called FindIntersectingLink or IsIntersectingRectTransform in TMP_TextUtilities. I tried to find the TMP_TextUtilities script, but I cannot find it anywhere :(

    So I wonder if anyone can pointing out to me where is TMP_TextUtilities located? And perhaps tell me how to fix the code? :)

    Many thanks in advance!
     

    Attached Files:

  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I would suggest to first check if "isHoveringOver" is returning the correct value when hovering over the portions of the link that don't appear to change color correctly. This should be simply to do by setting a break point there in the debugger.

    If that above is returning the correct values, then check if the linkIndex is also correct.

    Let me know what the outcome of the above is.
     
  3. ConfusedCactus

    ConfusedCactus

    Joined:
    Jul 3, 2018
    Posts:
    19
    Hi Stephan, many thanks for your reply. I've tried your method and have fixed it now. It turns out my textbox before is too small, so everything overflows. I made my textbox much bigger than the text it contains, and it works fine now! Many thanks again :)
     
    lingARApp and Stephan_B like this.