Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

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,465
    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.
  3. nikescar

    nikescar

    Joined:
    Nov 16, 2011
    Posts:
    150
    When can we expect this functionality (shouldActivateOnSelect)?

    I'm on 2021.3.4 and the latest version of TMP available is 3.0.6. It seems this wasn't added until 3.2.0 but I don't access to that version. Anyway to get that package or 4.0?
     
  4. nikescar

    nikescar

    Joined:
    Nov 16, 2011
    Posts:
    150
    I just decided to do it: Gist Here

    - Added shouldActivateOnSelect (disabled by default)
    - Added OnFocus (works much better to display an on screen keyboard here instead of OnSelect)

     
  5. nikescar

    nikescar

    Joined:
    Nov 16, 2011
    Posts:
    150
    Yeah, no. While this does work as far as the code, Unity really doesn't like when you move the TextMeshPro package into Assets. Had nothing but trouble with Unity Package Manager not knowing where some assets are coming from. Sooooo....

    Any chance that 3.2.0 will be released for Unity 2021, @Stephan_B?
     
    amynox likes this.
  6. amynox

    amynox

    Joined:
    Oct 23, 2016
    Posts:
    164
    +1 @Stephan_B ! When can we expect shouldActivateOnSelect ?
     
  7. nikescar

    nikescar

    Joined:
    Nov 16, 2011
    Posts:
    150
    Is this on anyone's radar or has UI/TMP development ceased?
     
    Keitaro_Ura likes this.
unityunity