Home > Back-end >  TMP_TextUtilities fails to find entire link string
TMP_TextUtilities fails to find entire link string

Time:10-20

I'm constructing links in certain texts in my game, using the <link> tag with TMP. These links contains a GUID in order to identify what it is pointing to.

<link=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>Some text</link>

This is working for my most part but when there a e in the GUID TMP cuts off at the first occurrence, so for example if there was an e at position 10 TMP only manages to return the 10 first characters in the GUID.
This is what happens:

xxxxxxxx-xxex-xxxx-xxxx-xxxxxxxxxxxx
xxxxxxxx-xx

The method generating the text

    public string CharacterLink(CharacterInfo info)
    {
        return $"<color={characterColor.Format()}><link={info.Id}>{info.Fullname}</link></color>";
    }

The methods for fetching the link

    public Entity GetLinkCharacter(TextMeshProUGUI text)
    {
        TMP_LinkInfo info = GetLink(text);
        if (info.Equals(default(TMP_LinkInfo)))
        {
            return null;
        }

        return entities.GetEntity(Guid.Parse(info.GetLinkID()));
    }

    private TMP_LinkInfo GetLink(TextMeshProUGUI text)
    {
        int index = TMP_TextUtilities.FindIntersectingLink(text, Input.mousePosition, null);
        if (index == -1)
        {
            return default;
        }

        return text.textInfo.linkInfo[index];
    }

Whenever there's an e in the GUID it throws an exception every time it tries to parse it since the GUID gets cut off on the first occurrence of an e.

CodePudding user response:

The lack of quotation marks was the issue. Silly me forgot to add them.

public string CharacterLink(CharacterInfo info)
{
    return $"<color={characterColor.Format()}><link={info.Id}>{info.Fullname}</link></color>";
}

had to be converted into this

public string CharacterLink(CharacterInfo info)
{
    return $"<color=\"{characterColor.Format()}\"><link=\"{info.Id}\">{info.Fullname}</link></color>";
}
  • Related