docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class TMP_TextUtilities

    Inheritance
    object
    TMP_TextUtilities
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: TMPro
    Assembly: Unity.TextMeshPro.dll
    Syntax
    public static class TMP_TextUtilities

    Methods

    DistanceToLine(Vector3, Vector3, Vector3)

    Method returning the Square Distance from a Point to a Line.

    Declaration
    public static float DistanceToLine(Vector3 a, Vector3 b, Vector3 point)
    Parameters
    Type Name Description
    Vector3 a

    First endpoint of the segment in the same space as the test point.

    Vector3 b

    Second endpoint of the segment; when equal to a the method returns squared distance to that point.

    Vector3 point

    Sample position whose closest point on the segment ab is projected to minimize Euclidean distance.

    Returns
    Type Description
    float

    Squared distance from point to the closest location on segment ab, avoiding a costly square root.

    Remarks

    Used heavily by caret picking to compare proximity to each edge of glyph quads without allocating temporary structs.

    FindIntersectingCharacter(TMP_Text, Vector3, Camera, bool)

    Method returning the index of the character at the given position (if any). Returns @@-1@@ if no character is found at the specified position.

    Declaration
    public static int FindIntersectingCharacter(TMP_Text text, Vector3 position, Camera camera, bool visibleOnly)
    Parameters
    Type Name Description
    TMP_Text text

    A reference to the TextMeshPro component.

    Vector3 position

    Position to check for intersection.

    Camera camera

    The scene camera which is rendering the text or whichever one might be assigned to a Canvas using ScreenSpace Camera or WorldSpace render mode. Set to null is using ScreenSpace Overlay.

    bool visibleOnly

    Only check for visible characters.

    Returns
    Type Description
    int

    Character index if intersecting, -1 otherwise.

    Remarks

    Iterates every character quad until one contains the point, skipping invisible glyphs when visibleOnly is enabled for lightweight hit tests.

    FindIntersectingLine(TMP_Text, Vector3, Camera)

    Method returning the line intersecting the position.

    Declaration
    public static int FindIntersectingLine(TMP_Text text, Vector3 position, Camera camera)
    Parameters
    Type Name Description
    TMP_Text text

    The text component.

    Vector3 position

    Position to check for intersection.

    Camera camera

    The scene camera which may be assigned to a Canvas using ScreenSpace Camera or WorldSpace render mode. Set to null is using ScreenSpace Overlay.

    Returns
    Type Description
    int

    First line whose ascender and descender straddle the vertical position, or -1 when no line contains the point.

    Remarks

    Unlike FindNearestLine(TMP_Text, Vector3, Camera) this returns -1 instead of a closest line when the pointer sits outside all bands.

    FindIntersectingLink(TMP_Text, Vector3, Camera)

    Method returning the index of the Link at the given position (if any).

    Declaration
    public static int FindIntersectingLink(TMP_Text text, Vector3 position, Camera camera)
    Parameters
    Type Name Description
    TMP_Text text

    A reference to the TMP_Text component.

    Vector3 position

    Position to check for intersection.

    Camera camera

    The scene camera which may be assigned to a Canvas using ScreenSpace Camera or WorldSpace render mode. Set to null is using ScreenSpace Overlay.

    Returns
    Type Description
    int

    Zero-based link index from textInfo when the point hits link geometry, otherwise -1.

    Remarks

    Honors page filters so overflow pages do not report links that belong to hidden sheets.

    FindIntersectingWord(TMP_Text, Vector3, Camera)

    Method returning the index of the word at the given position (if any).

    Declaration
    public static int FindIntersectingWord(TMP_Text text, Vector3 position, Camera camera)
    Parameters
    Type Name Description
    TMP_Text text

    A reference to the TMP_Text component.

    Vector3 position

    Position to check for intersection.

    Camera camera

    The scene camera which may be assigned to a Canvas using ScreenSpace Camera or WorldSpace render mode. Set to null is using ScreenSpace Overlay.

    Returns
    Type Description
    int

    Zero-based word index when the pointer lies inside the word bounds, or -1 when no word region contains the point.

    Remarks

    Builds axis-aligned bounds per word segment, including multi-line words, and returns on the first intersecting quad.

    FindNearestCharacter(TMP_Text, Vector3, Camera, bool)

    Method to find the nearest character to position.

    Declaration
    public static int FindNearestCharacter(TMP_Text text, Vector3 position, Camera camera, bool visibleOnly)
    Parameters
    Type Name Description
    TMP_Text text

    A reference to the TMP Text component.

    Vector3 position

    Position to check for intersection.

    Camera camera

    The scene camera which may be assigned to a Canvas using ScreenSpace Camera or WorldSpace render mode. Set to null is using ScreenSpace Overlay.

    bool visibleOnly

    Only check for visible characters.

    Returns
    Type Description
    int

    Zero-based character index in textInfo whose quad is closest by edge distance.

    Remarks

    Returns immediately when a quad contains the point; otherwise it tracks the minimum distance-to-edge metric across all candidate glyphs.

    FindNearestCharacterOnLine(TMP_Text, Vector3, int, Camera, bool)

    Method returning the nearest character to position on a given line.

    Declaration
    public static int FindNearestCharacterOnLine(TMP_Text text, Vector3 position, int line, Camera camera, bool visibleOnly)
    Parameters
    Type Name Description
    TMP_Text text

    TMP instance whose character metrics are used for the search.

    Vector3 position

    Position converted into the RectTransform space before distance tests.

    int line

    Zero-based line index previously returned from FindNearestLine(TMP_Text, Vector3, Camera).

    Camera camera

    Camera used for screen to world conversion; null for overlay canvases.

    bool visibleOnly

    Skips characters marked not visible when true, keeping invisible placeholders out of hit results.

    Returns
    Type Description
    int

    Character index within textInfo constrained to the requested line.

    Remarks

    Chooses the glyph rectangle that contains the point when possible; otherwise it minimizes squared distance to the quad edges for caret placement.

    FindNearestLine(TMP_Text, Vector3, Camera)

    Method returning the line nearest to the position.

    Declaration
    public static int FindNearestLine(TMP_Text text, Vector3 position, Camera camera)
    Parameters
    Type Name Description
    TMP_Text text

    TMP instance whose textInfo line metrics define bounds.

    Vector3 position

    Pointer or world position converted through the RectTransform before comparison.

    Camera camera

    Camera used to project screen points; null when the canvas is screen-space overlay.

    Returns
    Type Description
    int

    Zero-based line index when inside vertical bounds, otherwise the closest line by vertical distance.

    Remarks

    Prefers the line whose ascender and descender contain the point, falling back to whichever line minimizes vertical distance when the point sits between rows.

    FindNearestLink(TMP_Text, Vector3, Camera)

    Method returning the index of the link at the given position (if any).

    Declaration
    public static int FindNearestLink(TMP_Text text, Vector3 position, Camera camera)
    Parameters
    Type Name Description
    TMP_Text text

    A reference to the TMP_Text component.

    Vector3 position

    Position to check for intersection.

    Camera camera

    The scene camera which may be assigned to a Canvas using ScreenSpace Camera or WorldSpace render mode. Set to null is using ScreenSpace Overlay.

    Returns
    Type Description
    int

    Zero-based link index minimizing distance to the link bounds when the pointer is near but not inside a region.

    Remarks

    Mirrors the word nearest algorithm but operates on link spans so hover highlights can snap to the closest rich-text anchor.

    FindNearestWord(TMP_Text, Vector3, Camera)

    Method returning the index of the word at the given position (if any).

    Declaration
    public static int FindNearestWord(TMP_Text text, Vector3 position, Camera camera)
    Parameters
    Type Name Description
    TMP_Text text

    A reference to the TMP_Text component.

    Vector3 position

    Position to check for intersection.

    Camera camera

    The scene camera which may be assigned to a Canvas using ScreenSpace Camera or WorldSpace render mode. Set to null is using ScreenSpace Overlay.

    Returns
    Type Description
    int

    Zero-based word index whose bounds minimize edge distance when the point is outside every word quad.

    Remarks

    Similar to character picking but aggregates metrics per word region so tooltips can snap to whole tokens instead of individual glyphs.

    GetCursorIndexFromPosition(TMP_Text, Vector3, Camera)

    Method returning the index of the character whose origin is closest to the cursor.

    Declaration
    public static int GetCursorIndexFromPosition(TMP_Text textComponent, Vector3 position, Camera camera)
    Parameters
    Type Name Description
    TMP_Text textComponent

    A reference to the text object.

    Vector3 position

    Position to check for intersection.

    Camera camera

    The scene camera which may be assigned to a Canvas using ScreenSpace Camera or WorldSpace render mode. Set to null is using ScreenSpace Overlay.

    Returns
    Type Description
    int

    Character index for cursor insertion.

    Remarks

    Combines nearest-character search with horizontal placement within the glyph so caret insertion lands before or after the glyph center when clicking.

    GetCursorIndexFromPosition(TMP_Text, Vector3, Camera, out CaretPosition)

    Method returning the index of the character whose origin is closest to the cursor.

    Declaration
    public static int GetCursorIndexFromPosition(TMP_Text textComponent, Vector3 position, Camera camera, out CaretPosition cursor)
    Parameters
    Type Name Description
    TMP_Text textComponent

    A reference to the text object.

    Vector3 position

    Position to check for intersection.

    Camera camera

    The scene camera which may be assigned to a Canvas using ScreenSpace Camera or WorldSpace render mode. Set to null is using ScreenSpace Overlay.

    CaretPosition cursor

    The position of the cursor insertion position relative to the position.

    Returns
    Type Description
    int

    The index of the character whose origin is closest to the cursor.

    Remarks

    Resolves the line first, then picks the nearest glyph on that line and splits left versus right using the midpoint between the glyph corners.

    GetHashCode(string)

    Returns the case insensitive hashcode for the given string.

    Declaration
    public static int GetHashCode(string s)
    Parameters
    Type Name Description
    string s

    The string to hash.

    Returns
    Type Description
    int

    32-bit hash code combining uppercased ASCII letters so differently cased keys collide intentionally.

    Remarks

    Applies the same mixing polynomial used elsewhere in TMP for stable font feature lookups across platforms.

    GetHashCodeCaseInSensitive(string)

    Function which returns a simple hash code from a string converted to uppercase.

    Declaration
    public static uint GetHashCodeCaseInSensitive(string s)
    Parameters
    Type Name Description
    string s

    The string from which to compute the hash code.

    Returns
    Type Description
    uint

    The computed hash code.

    GetSimpleHashCode(string)

    Method which returns a simple hashcode from a string.

    Declaration
    public static int GetSimpleHashCode(string s)
    Parameters
    Type Name Description
    string s

    The string to hash.

    Returns
    Type Description
    int

    Iteratively mixed hash bits using each character code unit without case folding.

    Remarks

    Faster than the case-insensitive variant when the caller already normalized casing.

    GetSimpleHashCodeLowercase(string)

    Method which returns a simple hashcode from a string converted to lowercase.

    Declaration
    public static uint GetSimpleHashCodeLowercase(string s)
    Parameters
    Type Name Description
    string s

    The string to hash (converted to lowercase).

    Returns
    Type Description
    uint

    Unsigned DJB-style accumulation after folding ASCII characters through the fast lowercase table.

    Remarks

    Matches legacy TMP asset bundle keys that were persisted with lowercase folding for case-insensitive lookups.

    HexToInt(char)

    Method to convert Hex to Int

    Declaration
    public static int HexToInt(char hex)
    Parameters
    Type Name Description
    char hex

    Single hexadecimal digit character drawn from ASCII ranges 0-9, A-F, or a-f.

    Returns
    Type Description
    int

    Integer nibble value from 0 through 15, or 15 when the character does not match a known hex digit.

    Remarks

    Fallback to 15 keeps legacy callers from throwing when parsing partially malformed rich-text color attributes.

    IsIntersectingRectTransform(RectTransform, Vector3, Camera)

    Method used to determine if the position intersects with the RectTransform.

    Declaration
    public static bool IsIntersectingRectTransform(RectTransform rectTransform, Vector3 position, Camera camera)
    Parameters
    Type Name Description
    RectTransform rectTransform

    A reference to the RectTranform of the text object.

    Vector3 position

    Position to check for intersection.

    Camera camera

    The scene camera which may be assigned to a Canvas using ScreenSpace Camera or WorldSpace render mode. Set to null is using ScreenSpace Overlay.

    Returns
    Type Description
    bool

    Whether the transformed point lies inside the world-space rectangle described by the four corners.

    Remarks

    Projects the point through ScreenPointToWorldPointInRectangle(Transform, Vector2, Camera, out Vector3) then tests against the cached world corners from GetWorldCorners(Vector3[]).

    ScreenPointToWorldPointInRectangle(Transform, Vector2, Camera, out Vector3)

    Method to convert ScreenPoint to WorldPoint aligned with Rectangle

    Declaration
    public static bool ScreenPointToWorldPointInRectangle(Transform transform, Vector2 screenPoint, Camera cam, out Vector3 worldPoint)
    Parameters
    Type Name Description
    Transform transform

    RectTransform (or Transform) to convert into.

    Vector2 screenPoint

    Screen-space position.

    Camera cam

    Camera; null for overlay canvas.

    Vector3 worldPoint

    Resulting world position on the plane defined by the transform.

    Returns
    Type Description
    bool

    Whether a ray from the camera intersects the plane defined by the transform orientation and position.

    Remarks

    Builds a plane using the transform forward and projects the screen ray to recover a world-space point suitable for RectTransform hit tests.

    StringHexToInt(string)

    Method to convert a properly formatted string which contains an hex value to its decimal value.

    Declaration
    public static int StringHexToInt(string s)
    Parameters
    Type Name Description
    string s

    String containing hexadecimal digits without leading prefixes; processed from most significant nibble.

    Returns
    Type Description
    int

    Combined integer value after multiplying each nibble by successive powers of sixteen.

    Remarks

    Powers characters using Pow(float, float) so multi-byte color strings become single ARGB component values.

    ToLowerFast(char)

    Get lowercase version of this ASCII character.

    Declaration
    public static char ToLowerFast(char c)
    Parameters
    Type Name Description
    char c
    Returns
    Type Description
    char

    ToUpperFast(char)

    Get uppercase version of this ASCII character.

    Declaration
    public static char ToUpperFast(char c)
    Parameters
    Type Name Description
    char c
    Returns
    Type Description
    char
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)