Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question which event or method is raised in tmp input fields when pressing enter ?

Discussion in 'UGUI & TextMesh Pro' started by kasmurdanto, Dec 7, 2023.

  1. kasmurdanto

    kasmurdanto

    Joined:
    Jun 6, 2019
    Posts:
    10
    So I'd like to trigger some method when the user presses enter while editing an input field.
    I inherited from it and put it like that :
    Code (CSharp):
    1.    
    2.  /// <summary>
    3.     /// TMP input field, with the added functionnality of toggling controls on and off when the field is selected or deselected.
    4.    /// </summary>
    5.     public class ControlsOffInputField : TMP_InputField
    6.     {
    7.         public override void OnSelect(BaseEventData eventData)
    8.         {
    9.             base.OnSelect(eventData);
    10.             Subsystems.Get<InputSystem>().ToggleAllActions(false);
    11.         }
    12.  
    13.         public override void OnDeselect(BaseEventData eventData)
    14.         {
    15.             base.OnDeselect(eventData);
    16.             Subsystems.Get<InputSystem>().ToggleAllActions(true);
    17.         }
    18.     }
    I was expecting OnDeselect to get called when pressing enter but it dit not do it. I tried with OnSubmit, no luck either. What should I do ?