Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.

    Read our full announcement for more information and let us know if you have any questions.

Bug Long URL breaks link tag

Discussion in 'UGUI & TextMesh Pro' started by xucian, Sep 12, 2023.

  1. xucian


    Mar 7, 2016

    Seems odd that I might be the first to find about this, but I simply can't have "long" links in TMPro.
    Using v3.0.6


    Expected render:

    Actual render:

    - Happens in v3.2.0-pre.4 too
    - Using Unity 2022.1.24f1
    Last edited: Sep 14, 2023
  2. xucian


    Mar 7, 2016
  3. xucian


    Mar 7, 2016
    Alright, I've found the culprit, links over ~120 chars are not supported out of the box, it's a pretty huge limitation.
    I understand that links can be shorter and you can have a mapping in code, but that's seems unnecessarily complicated.

    I've added this code to my current project to increase it to 1024 chars:
    Code (CSharp):
    2.     private const int RICH_TEXT_TAG_LENGTH_OVERRIDE = 1024;
    3. #if UNITY_EDITOR
    4.     [UnityEditor.InitializeOnLoadMethod]
    5. #else
    6.     [RuntimeInitializeOnLoadMethod]
    7. #endif
    8.     static void TryFixTMProTagLength()
    9.     {
    10.         // Fixing TMPro to have a bigger tag length. Currently it's just 128 which is peanuts - links can be very long.
    11.         // More specifically, the link tag breaks if the text inside the tag is longer than 128 chars, eg:
    12.         // For <link="http://..">
    13.         // <whatever_is_here_has_to_be_shorter_than_128_chars>
    14.         var fi = typeof(TMP_Text).GetField("m_htmlTag", BindingFlags.NonPublic | BindingFlags.Static);
    15.         var arr = fi.GetValue(null) as char[];
    16.         if (arr.Length < RICH_TEXT_TAG_LENGTH_OVERRIDE)
    17.         {
    18.             Array.Resize(ref arr, RICH_TEXT_TAG_LENGTH_OVERRIDE);
    19.             fi.SetValue(null, arr);
    20.         }
    21.     }
    Link to the latest revision: github