Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

TMP_InputField always activates onSelect (unlike unity InputField which can be configured)

Discussion in 'UGUI & TextMesh Pro' started by isaac-ashdown, Jun 23, 2021.

  1. isaac-ashdown

    isaac-ashdown

    Joined:
    Jan 30, 2019
    Posts:
    69
    TMP_InputField.OnSelect:

    Code (CSharp):
    1.         public override void OnSelect(BaseEventData eventData)
    2.         {
    3.             //Debug.Log("OnSelect()");
    4.  
    5.             base.OnSelect(eventData);
    6.             SendOnFocus();
    7.  
    8.             ActivateInputField();
    9.         }
    But unity InputField.OnSelect looks like this:

    Code (CSharp):
    1.         public override void OnSelect(BaseEventData eventData)
    2.         {
    3.             base.OnSelect(eventData);
    4.  
    5.             if (shouldActivateOnSelect)
    6.                 ActivateInputField();
    7.         }
    Note it exposes a public properly shouldActivateOnSelect that can be set to false at runtime when you don't want this behaviour. It would be good if the TMP version also had this functionality.

    Note that it's not possible to just override OnSelect and call DeactivateInputField after calling the base.OnSelect, because ActivateInputField sets a private bool m_ShouldActivateNextUpdate which doesn't get set to false in DeactivateInputField. So I have to do this in my derived class which isn't so nice:

    Code (CSharp):
    1.     public class DebugInputField : TMPro.TMP_InputField
    2.     {
    3.         bool deactivateOnNextUpdate = false;
    4.  
    5.         public override void OnSelect(BaseEventData eventData)
    6.         {
    7.             base.OnSelect(eventData);
    8.             deactivateOnNextUpdate = true;
    9.         }
    10.  
    11.         protected override void LateUpdate()
    12.         {
    13.             base.LateUpdate();
    14.             if (deactivateOnNextUpdate)
    15.             {
    16.                 deactivateOnNextUpdate = false;
    17.                 DeactivateInputField();
    18.             }
    19.         }
    20.     }
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,265
    I recently added this new property to the TMP Input Field which will be available in the next preview release which I hope to have available within the next 10 to 14 days.
     
    isaac-ashdown likes this.
unityunity