Search Unity

TextMesh Pro TMP_InputField ActivateInputField is not working in OnEnable

Discussion in 'UGUI & TextMesh Pro' started by Frimus, Mar 27, 2022.

  1. Frimus

    Frimus

    Joined:
    May 28, 2014
    Posts:
    6
    I am trying to select a Selectable (in this context it is a TMP_InputField ) in the script as follows:

    Code (CSharp):
    1.  
    2. // Current interactable and focused component (Assigned from Inspector)
    3. private Selectable currentSelectable;
    4.  
    5. private void OnEnable(){
    6.   // Selecting the assigned selectable
    7.   currentSelectable.Select();
    8.   currentSelectable.OnSelect(null);
    9. }
    Inside OnSelect(...) of TMP_InputField, I have provided a way to change colours so that it appears as selected, as shown in snippet below:

    Code (CSharp):
    1. // Called when email input is selected
    2. public void SelectEmailGroup(){
    3.   Colors.SetColor(emailGroup, "blue");
    4.   Colors.SetColor(passwordGroup, "gray");
    5.   email.ActivateInputField(); // This line has no effect on the email Input Field
    6. }
    The above method SelectEmailGroup() is assigned to OnSelect(string) method of TMP_InputField via Inspector

    Even though the colours are updated on the TMP_InputField, still I am unable to get the focus on it to enter via keyboard. I have to press <kbd>ENTER</kbd> key before doing so.

    Kindly suggest some direction on the topic.