Clickable Links in Unity Text: Hover, Click and URLs

Last reviewed

Short answer

TextMesh Pro marks links with a <link> tag but leaves the rest to your code: finding which link the pointer is over, hover and pressed styling, and opening the URL.

UniText ships links as a ready style: <link=url> tags, Markdown [text](url) and bare URLs become clickable with hover and pressed states, open in the browser by default and raise click and hover events, on canvas and world-space text alike.

The usual options

  • TextMesh Pro. The <link> tag stores an ID and does not change how the text looks. TMP_TextUtilities.FindIntersectingLink returns which link is under a point; click handling, hover and pressed colors and opening the URL are your code. The bundled example scripts handle hover only and read the legacy Input class, which throws when a project uses only the Input System.
  • UI Toolkit. An <a href> link opens its URL on click. A <link> tag raises pointer events that are still marked experimental, and hover styling is done by hand with inline color tags and USS classes.
  • Helper libraries. Open-source helpers such as FancyTextRendering add normal, hover and click colors and click actions on top of TextMesh Pro's link tags.

How UniText handles links

  • Three ways to write a link. LinkModifier with its parse rules recognizes explicit <link=url> tags, Markdown [text](url) and bare addresses such as https://, www., mailto: and tel:.
  • Behavior included. With AutoOpenUrl on, a click opens the URL through Application.OpenURL. LinkClicked, LinkEntered and LinkExited fire for your own handling.
  • States and styling. Each link range moves through Normal, Hovered, Pressed and Disabled, and the built-in link preset combines color, underline and highlight with rules for each state.
  • Any interactive range. The same machinery drives spoilers, @mentions and #tags detected automatically, and your own clickable ranges carrying an ID or an object payload, with keyboard navigation and long-press.
  • Scroll views and world space. Viewport adapters keep hit-testing correct inside a ScrollRect and for world-space text seen by a camera.
csharp
using LightSide;
using UnityEngine;

public sealed class ProfileLinks : MonoBehaviour
{
    [SerializeField] UniTextBase text;
    [SerializeField] RangeChannel channel;
    RangeInteractionEvents events;

    void OnEnable()
    {
        events = UniTextInteractions.For(text).Get(channel);
        events.Activated += OnActivated;
    }

    void OnDisable() => events.Activated -= OnActivated;

    void OnActivated(RangeInteraction interaction)
        => Debug.Log($"Open profile {interaction.Range.PrimaryValue}", text);
}

Questions

Can a link open something inside the game instead of a browser?

Yes. Turn off AutoOpenUrl or use a plain interactive range, and handle the click in code with the range's value, such as a user ID or an item key.

Do links work inside right-to-left text?

Yes. Hit-testing follows the laid-out glyphs, so a link inside Arabic or Hebrew text is clicked where it is drawn.

Can players select and copy linked text?

Yes, with the selectable or editable components. Copying keeps links as Markdown or HTML when the destination accepts formatting.

Check it in your project

Run the browser demo, follow the setup guide, or compare the free version with the licenses.

Related problems