docs.unity3d.com
    Show / Hide Table of Contents

    Class TMP_InputField

    Editable text input field.

    Inheritance
    System.Object
    UnityEngine.EventSystems.UIBehaviour
    UnityEngine.UI.Selectable
    TMP_InputField
    Inherited Members
    UnityEngine.UI.Selectable.s_Selectables
    UnityEngine.UI.Selectable.s_SelectableCount
    UnityEngine.UI.Selectable.m_CurrentIndex
    UnityEngine.UI.Selectable.AllSelectablesNoAlloc(UnityEngine.UI.Selectable[])
    UnityEngine.UI.Selectable.Awake()
    UnityEngine.UI.Selectable.OnCanvasGroupChanged()
    UnityEngine.UI.Selectable.IsInteractable()
    UnityEngine.UI.Selectable.OnDidApplyAnimationProperties()
    UnityEngine.UI.Selectable.OnTransformParentChanged()
    UnityEngine.UI.Selectable.OnValidate()
    UnityEngine.UI.Selectable.Reset()
    UnityEngine.UI.Selectable.InstantClearState()
    UnityEngine.UI.Selectable.FindSelectable(UnityEngine.Vector3)
    UnityEngine.UI.Selectable.FindSelectableOnLeft()
    UnityEngine.UI.Selectable.FindSelectableOnRight()
    UnityEngine.UI.Selectable.FindSelectableOnUp()
    UnityEngine.UI.Selectable.FindSelectableOnDown()
    UnityEngine.UI.Selectable.OnMove(UnityEngine.EventSystems.AxisEventData)
    UnityEngine.UI.Selectable.IsHighlighted()
    UnityEngine.UI.Selectable.IsPressed()
    UnityEngine.UI.Selectable.OnPointerUp(UnityEngine.EventSystems.PointerEventData)
    UnityEngine.UI.Selectable.OnPointerEnter(UnityEngine.EventSystems.PointerEventData)
    UnityEngine.UI.Selectable.OnPointerExit(UnityEngine.EventSystems.PointerEventData)
    UnityEngine.UI.Selectable.Select()
    UnityEngine.UI.Selectable.allSelectablesArray
    UnityEngine.UI.Selectable.allSelectableCount
    UnityEngine.UI.Selectable.allSelectables
    UnityEngine.UI.Selectable.navigation
    UnityEngine.UI.Selectable.transition
    UnityEngine.UI.Selectable.colors
    UnityEngine.UI.Selectable.spriteState
    UnityEngine.UI.Selectable.animationTriggers
    UnityEngine.UI.Selectable.targetGraphic
    UnityEngine.UI.Selectable.interactable
    UnityEngine.UI.Selectable.image
    UnityEngine.UI.Selectable.animator
    UnityEngine.UI.Selectable.currentSelectionState
    UnityEngine.EventSystems.UIBehaviour.Start()
    UnityEngine.EventSystems.UIBehaviour.OnDestroy()
    UnityEngine.EventSystems.UIBehaviour.IsActive()
    UnityEngine.EventSystems.UIBehaviour.OnRectTransformDimensionsChange()
    UnityEngine.EventSystems.UIBehaviour.OnBeforeTransformParentChanged()
    UnityEngine.EventSystems.UIBehaviour.OnCanvasHierarchyChanged()
    UnityEngine.EventSystems.UIBehaviour.IsDestroyed()
    Namespace: TMPro
    Syntax
    [AddComponentMenu("UI/TextMeshPro - Input Field", 11)]
    public class TMP_InputField : Selectable, IMoveHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, IUpdateSelectedHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler, ISubmitHandler, ICanvasElement, IScrollHandler, IEventSystemHandler

    Constructors

    TMP_InputField()

    Declaration
    protected TMP_InputField()

    Fields

    m_CaretPosition

    Declaration
    protected int m_CaretPosition
    Field Value
    Type Description
    System.Int32

    m_CaretSelectPosition

    Declaration
    protected int m_CaretSelectPosition
    Field Value
    Type Description
    System.Int32

    m_CaretVisible

    Declaration
    protected bool m_CaretVisible
    Field Value
    Type Description
    System.Boolean

    m_CursorVerts

    Declaration
    protected UIVertex[] m_CursorVerts
    Field Value
    Type Description
    UIVertex[]

    m_GlobalFontAsset

    Declaration
    [SerializeField]
    protected TMP_FontAsset m_GlobalFontAsset
    Field Value
    Type Description
    TMP_FontAsset

    m_InputValidator

    Declaration
    [SerializeField]
    protected TMP_InputValidator m_InputValidator
    Field Value
    Type Description
    TMP_InputValidator

    m_isRichTextEditingAllowed

    Declaration
    [SerializeField]
    protected bool m_isRichTextEditingAllowed
    Field Value
    Type Description
    System.Boolean

    m_isSelectAll

    Declaration
    protected bool m_isSelectAll
    Field Value
    Type Description
    System.Boolean

    m_Keyboard

    Declaration
    protected TouchScreenKeyboard m_Keyboard
    Field Value
    Type Description
    TouchScreenKeyboard

    m_Mesh

    Declaration
    [NonSerialized]
    protected Mesh m_Mesh
    Field Value
    Type Description
    Mesh

    m_OnFocusSelectAll

    Declaration
    [SerializeField]
    protected bool m_OnFocusSelectAll
    Field Value
    Type Description
    System.Boolean

    m_Placeholder

    Declaration
    [SerializeField]
    protected Graphic m_Placeholder
    Field Value
    Type Description
    UnityEngine.UI.Graphic

    m_ResetOnDeActivation

    Declaration
    [SerializeField]
    protected bool m_ResetOnDeActivation
    Field Value
    Type Description
    System.Boolean

    m_ScrollSensitivity

    Declaration
    [SerializeField]
    protected float m_ScrollSensitivity
    Field Value
    Type Description
    System.Single

    m_StringPosition

    Declaration
    protected int m_StringPosition
    Field Value
    Type Description
    System.Int32

    m_StringSelectPosition

    Declaration
    protected int m_StringSelectPosition
    Field Value
    Type Description
    System.Int32

    m_Text

    Input field's value.

    Declaration
    [SerializeField]
    [TextArea(3, 10)]
    protected string m_Text
    Field Value
    Type Description
    System.String

    m_TextComponent

    Declaration
    [SerializeField]
    protected TMP_Text m_TextComponent
    Field Value
    Type Description
    TMP_Text

    m_TextComponentRectTransform

    Declaration
    protected RectTransform m_TextComponentRectTransform
    Field Value
    Type Description
    RectTransform

    m_TextViewport

    Text Text used to display the input's value.

    Declaration
    [SerializeField]
    protected RectTransform m_TextViewport
    Field Value
    Type Description
    RectTransform

    m_VerticalScrollbar

    Declaration
    [SerializeField]
    protected Scrollbar m_VerticalScrollbar
    Field Value
    Type Description
    UnityEngine.UI.Scrollbar

    m_VerticalScrollbarEventHandler

    Declaration
    [SerializeField]
    protected TMP_ScrollbarEventHandler m_VerticalScrollbarEventHandler
    Field Value
    Type Description
    TMP_ScrollbarEventHandler

    Properties

    asteriskChar

    Declaration
    public char asteriskChar { get; set; }
    Property Value
    Type Description
    System.Char

    caretBlinkRate

    Declaration
    public float caretBlinkRate { get; set; }
    Property Value
    Type Description
    System.Single

    caretColor

    Declaration
    public Color caretColor { get; set; }
    Property Value
    Type Description
    Color

    caretPosition

    Get: Returns the focus position as thats the position that moves around even during selection. Set: Set both the anchor and focus position such that a selection doesn't happen

    Declaration
    public int caretPosition { get; set; }
    Property Value
    Type Description
    System.Int32

    caretPositionInternal

    Current position of the cursor. Getters are public Setters are protected

    Declaration
    protected int caretPositionInternal { get; set; }
    Property Value
    Type Description
    System.Int32

    caretSelectPositionInternal

    Declaration
    protected int caretSelectPositionInternal { get; set; }
    Property Value
    Type Description
    System.Int32

    caretWidth

    Declaration
    public int caretWidth { get; set; }
    Property Value
    Type Description
    System.Int32

    characterLimit

    Declaration
    public int characterLimit { get; set; }
    Property Value
    Type Description
    System.Int32

    characterValidation

    Declaration
    public TMP_InputField.CharacterValidation characterValidation { get; set; }
    Property Value
    Type Description
    TMP_InputField.CharacterValidation

    contentType

    Declaration
    public TMP_InputField.ContentType contentType { get; set; }
    Property Value
    Type Description
    TMP_InputField.ContentType

    customCaretColor

    Declaration
    public bool customCaretColor { get; set; }
    Property Value
    Type Description
    System.Boolean

    fontAsset

    Sets the Font Asset on both Placeholder and Input child objects.

    Declaration
    public TMP_FontAsset fontAsset { get; set; }
    Property Value
    Type Description
    TMP_FontAsset

    inputType

    Declaration
    public TMP_InputField.InputType inputType { get; set; }
    Property Value
    Type Description
    TMP_InputField.InputType

    inputValidator

    Sets the Input Validation to use a Custom Input Validation script.

    Declaration
    public TMP_InputValidator inputValidator { get; set; }
    Property Value
    Type Description
    TMP_InputValidator

    isFocused

    Declaration
    public bool isFocused { get; }
    Property Value
    Type Description
    System.Boolean

    isRichTextEditingAllowed

    Is Rich Text editing allowed?

    Declaration
    public bool isRichTextEditingAllowed { get; set; }
    Property Value
    Type Description
    System.Boolean

    keyboardType

    Declaration
    public TouchScreenKeyboardType keyboardType { get; set; }
    Property Value
    Type Description
    TouchScreenKeyboardType

    lineType

    Declaration
    public TMP_InputField.LineType lineType { get; set; }
    Property Value
    Type Description
    TMP_InputField.LineType

    mesh

    Declaration
    protected Mesh mesh { get; }
    Property Value
    Type Description
    Mesh

    multiLine

    Declaration
    public bool multiLine { get; }
    Property Value
    Type Description
    System.Boolean

    onDeselect

    Declaration
    public TMP_InputField.SelectionEvent onDeselect { get; set; }
    Property Value
    Type Description
    TMP_InputField.SelectionEvent

    onEndEdit

    Declaration
    public TMP_InputField.SubmitEvent onEndEdit { get; set; }
    Property Value
    Type Description
    TMP_InputField.SubmitEvent

    onEndTextSelection

    Declaration
    public TMP_InputField.TextSelectionEvent onEndTextSelection { get; set; }
    Property Value
    Type Description
    TMP_InputField.TextSelectionEvent

    onFocusSelectAll

    Determines if the whole text will be selected when focused.

    Declaration
    public bool onFocusSelectAll { get; set; }
    Property Value
    Type Description
    System.Boolean

    onSelect

    Declaration
    public TMP_InputField.SelectionEvent onSelect { get; set; }
    Property Value
    Type Description
    TMP_InputField.SelectionEvent

    onSubmit

    Declaration
    public TMP_InputField.SubmitEvent onSubmit { get; set; }
    Property Value
    Type Description
    TMP_InputField.SubmitEvent

    onTextSelection

    Declaration
    public TMP_InputField.TextSelectionEvent onTextSelection { get; set; }
    Property Value
    Type Description
    TMP_InputField.TextSelectionEvent

    onValidateInput

    Declaration
    public TMP_InputField.OnValidateInput onValidateInput { get; set; }
    Property Value
    Type Description
    TMP_InputField.OnValidateInput

    onValueChanged

    Declaration
    public TMP_InputField.OnChangeEvent onValueChanged { get; set; }
    Property Value
    Type Description
    TMP_InputField.OnChangeEvent

    placeholder

    Declaration
    public Graphic placeholder { get; set; }
    Property Value
    Type Description
    UnityEngine.UI.Graphic

    pointSize

    Set the point size on both Placeholder and Input text object.

    Declaration
    public float pointSize { get; set; }
    Property Value
    Type Description
    System.Single

    readOnly

    Declaration
    public bool readOnly { get; set; }
    Property Value
    Type Description
    System.Boolean

    resetOnDeActivation

    Determines if the text and caret position as well as selection will be reset when the input field is deactivated.

    Declaration
    public bool resetOnDeActivation { get; set; }
    Property Value
    Type Description
    System.Boolean

    restoreOriginalTextOnEscape

    Controls whether the original text is restored when pressing "ESC".

    Declaration
    public bool restoreOriginalTextOnEscape { get; set; }
    Property Value
    Type Description
    System.Boolean

    richText

    Declaration
    public bool richText { get; set; }
    Property Value
    Type Description
    System.Boolean

    scrollSensitivity

    Declaration
    public float scrollSensitivity { get; set; }
    Property Value
    Type Description
    System.Single

    selectionAnchorPosition

    Get: Returns the fixed position of selection Set: If Input.compositionString is 0 set the fixed position

    Declaration
    public int selectionAnchorPosition { get; set; }
    Property Value
    Type Description
    System.Int32

    selectionColor

    Declaration
    public Color selectionColor { get; set; }
    Property Value
    Type Description
    Color

    selectionFocusPosition

    Get: Returns the variable position of selection Set: If Input.compositionString is 0 set the variable position

    Declaration
    public int selectionFocusPosition { get; set; }
    Property Value
    Type Description
    System.Int32

    selectionStringAnchorPosition

    The fixed position of the selection in the raw string which may contains rich text.

    Declaration
    public int selectionStringAnchorPosition { get; set; }
    Property Value
    Type Description
    System.Int32

    selectionStringFocusPosition

    The variable position of the selection in the raw string which may contains rich text.

    Declaration
    public int selectionStringFocusPosition { get; set; }
    Property Value
    Type Description
    System.Int32

    shouldHideMobileInput

    Should the mobile keyboard input be hidden.

    Declaration
    public bool shouldHideMobileInput { get; set; }
    Property Value
    Type Description
    System.Boolean

    stringPosition

    Declaration
    public int stringPosition { get; set; }
    Property Value
    Type Description
    System.Int32

    stringPositionInternal

    Declaration
    protected int stringPositionInternal { get; set; }
    Property Value
    Type Description
    System.Int32

    stringSelectPositionInternal

    Declaration
    protected int stringSelectPositionInternal { get; set; }
    Property Value
    Type Description
    System.Int32

    text

    Input field's current text value.

    Declaration
    public string text { get; set; }
    Property Value
    Type Description
    System.String

    textComponent

    Declaration
    public TMP_Text textComponent { get; set; }
    Property Value
    Type Description
    TMP_Text

    textViewport

    Declaration
    public RectTransform textViewport { get; set; }
    Property Value
    Type Description
    RectTransform

    verticalScrollbar

    Declaration
    public Scrollbar verticalScrollbar { get; set; }
    Property Value
    Type Description
    UnityEngine.UI.Scrollbar

    wasCanceled

    Declaration
    public bool wasCanceled { get; }
    Property Value
    Type Description
    System.Boolean

    Methods

    ActivateInputField()

    Declaration
    public void ActivateInputField()

    Append(Char)

    Declaration
    protected virtual void Append(char input)
    Parameters
    Type Name Description
    System.Char input

    Append(String)

    Append the specified text to the end of the current.

    Declaration
    protected virtual void Append(string input)
    Parameters
    Type Name Description
    System.String input

    ClampCaretPos(ref Int32)

    Declaration
    protected void ClampCaretPos(ref int pos)
    Parameters
    Type Name Description
    System.Int32 pos

    ClampStringPos(ref Int32)

    Declaration
    protected void ClampStringPos(ref int pos)
    Parameters
    Type Name Description
    System.Int32 pos

    DeactivateInputField()

    Declaration
    public void DeactivateInputField()

    DoStateTransition(Selectable.SelectionState, Boolean)

    Declaration
    protected override void DoStateTransition(Selectable.SelectionState state, bool instant)
    Parameters
    Type Name Description
    UnityEngine.UI.Selectable.SelectionState state
    System.Boolean instant
    Overrides
    UnityEngine.UI.Selectable.DoStateTransition(UnityEngine.UI.Selectable.SelectionState, System.Boolean)

    ForceLabelUpdate()

    Declaration
    public void ForceLabelUpdate()

    GraphicUpdateComplete()

    Declaration
    public virtual void GraphicUpdateComplete()
    Implements
    UnityEngine.UI.ICanvasElement.GraphicUpdateComplete()

    KeyPressed(Event)

    Declaration
    protected TMP_InputField.EditState KeyPressed(Event evt)
    Parameters
    Type Name Description
    Event evt
    Returns
    Type Description
    TMP_InputField.EditState

    LateUpdate()

    Update the text based on input.

    Declaration
    protected virtual void LateUpdate()

    LayoutComplete()

    Declaration
    public virtual void LayoutComplete()
    Implements
    UnityEngine.UI.ICanvasElement.LayoutComplete()

    MoveTextEnd(Boolean)

    Move to the end of the text.

    Declaration
    public void MoveTextEnd(bool shift)
    Parameters
    Type Name Description
    System.Boolean shift

    MoveTextStart(Boolean)

    Move to the start of the text.

    Declaration
    public void MoveTextStart(bool shift)
    Parameters
    Type Name Description
    System.Boolean shift

    MoveToEndOfLine(Boolean, Boolean)

    Move to the end of the current line of text.

    Declaration
    public void MoveToEndOfLine(bool shift, bool ctrl)
    Parameters
    Type Name Description
    System.Boolean shift
    System.Boolean ctrl

    MoveToStartOfLine(Boolean, Boolean)

    Move to the start of the current line of text.

    Declaration
    public void MoveToStartOfLine(bool shift, bool ctrl)
    Parameters
    Type Name Description
    System.Boolean shift
    System.Boolean ctrl

    OnBeginDrag(PointerEventData)

    Declaration
    public virtual void OnBeginDrag(PointerEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.PointerEventData eventData
    Implements
    UnityEngine.EventSystems.IBeginDragHandler.OnBeginDrag(UnityEngine.EventSystems.PointerEventData)

    OnControlClick()

    Declaration
    public void OnControlClick()

    OnDeselect(BaseEventData)

    Declaration
    public override void OnDeselect(BaseEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.BaseEventData eventData
    Overrides
    UnityEngine.UI.Selectable.OnDeselect(UnityEngine.EventSystems.BaseEventData)

    OnDisable()

    Declaration
    protected override void OnDisable()
    Overrides
    UnityEngine.UI.Selectable.OnDisable()

    OnDrag(PointerEventData)

    Declaration
    public virtual void OnDrag(PointerEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.PointerEventData eventData
    Implements
    UnityEngine.EventSystems.IDragHandler.OnDrag(UnityEngine.EventSystems.PointerEventData)

    OnEnable()

    Declaration
    protected override void OnEnable()
    Overrides
    UnityEngine.UI.Selectable.OnEnable()

    OnEndDrag(PointerEventData)

    Declaration
    public virtual void OnEndDrag(PointerEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.PointerEventData eventData
    Implements
    UnityEngine.EventSystems.IEndDragHandler.OnEndDrag(UnityEngine.EventSystems.PointerEventData)

    OnFocus()

    Declaration
    protected void OnFocus()

    OnPointerClick(PointerEventData)

    Declaration
    public virtual void OnPointerClick(PointerEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.PointerEventData eventData
    Implements
    UnityEngine.EventSystems.IPointerClickHandler.OnPointerClick(UnityEngine.EventSystems.PointerEventData)

    OnPointerDown(PointerEventData)

    Declaration
    public override void OnPointerDown(PointerEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.PointerEventData eventData
    Overrides
    UnityEngine.UI.Selectable.OnPointerDown(UnityEngine.EventSystems.PointerEventData)

    OnScroll(PointerEventData)

    Declaration
    public virtual void OnScroll(PointerEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.PointerEventData eventData
    Implements
    UnityEngine.EventSystems.IScrollHandler.OnScroll(UnityEngine.EventSystems.PointerEventData)

    OnSelect(BaseEventData)

    Declaration
    public override void OnSelect(BaseEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.BaseEventData eventData
    Overrides
    UnityEngine.UI.Selectable.OnSelect(UnityEngine.EventSystems.BaseEventData)

    OnSubmit(BaseEventData)

    Declaration
    public virtual void OnSubmit(BaseEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.BaseEventData eventData
    Implements
    UnityEngine.EventSystems.ISubmitHandler.OnSubmit(UnityEngine.EventSystems.BaseEventData)

    OnUpdateSelected(BaseEventData)

    Declaration
    public virtual void OnUpdateSelected(BaseEventData eventData)
    Parameters
    Type Name Description
    UnityEngine.EventSystems.BaseEventData eventData
    Implements
    UnityEngine.EventSystems.IUpdateSelectedHandler.OnUpdateSelected(UnityEngine.EventSystems.BaseEventData)

    ProcessEvent(Event)

    Declaration
    public void ProcessEvent(Event e)
    Parameters
    Type Name Description
    Event e

    Rebuild(CanvasUpdate)

    Declaration
    public virtual void Rebuild(CanvasUpdate update)
    Parameters
    Type Name Description
    UnityEngine.UI.CanvasUpdate update
    Implements
    UnityEngine.UI.ICanvasElement.Rebuild(UnityEngine.UI.CanvasUpdate)

    SelectAll()

    Declaration
    protected void SelectAll()

    SendOnEndEdit()

    Submit the input field's text.

    Declaration
    protected void SendOnEndEdit()

    SendOnEndTextSelection()

    Declaration
    protected void SendOnEndTextSelection()

    SendOnFocus()

    Declaration
    protected void SendOnFocus()

    SendOnFocusLost()

    Declaration
    protected void SendOnFocusLost()

    SendOnSubmit()

    Declaration
    protected void SendOnSubmit()

    SendOnTextSelection()

    Declaration
    protected void SendOnTextSelection()

    SetGlobalFontAsset(TMP_FontAsset)

    Function to conveniently set the Font Asset of both Placeholder and Input Field text object.

    Declaration
    public void SetGlobalFontAsset(TMP_FontAsset fontAsset)
    Parameters
    Type Name Description
    TMP_FontAsset fontAsset

    SetGlobalPointSize(Single)

    Function to conveniently set the point size of both Placeholder and Input Field text object.

    Declaration
    public void SetGlobalPointSize(float pointSize)
    Parameters
    Type Name Description
    System.Single pointSize

    UpdateLabel()

    Update the visual text Text.

    Declaration
    protected void UpdateLabel()

    Validate(String, Int32, Char)

    Validate the specified input.

    Declaration
    protected char Validate(string text, int pos, char ch)
    Parameters
    Type Name Description
    System.String text
    System.Int32 pos
    System.Char ch
    Returns
    Type Description
    System.Char
    Back to top
    Copyright © 2025 Unity Technologies
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 02 April 2025