Search Unity

TMP_InputField not automatically active second time

Discussion in 'UGUI & TextMesh Pro' started by chico_barnstorm, Jul 19, 2019.

  1. chico_barnstorm

    chico_barnstorm

    Joined:
    Jun 11, 2014
    Posts:
    10
    Hi,

    It really feels like this sort of question should have been asked and resolved already in the past. But we have honestly failed to find it.

    The thing is, on a particular screen, we have a TMP_InputField that we activate in OnEnable() like this:

    Code (CSharp):
    1.      
    2. private void OnEnable()
    3. {
    4.     name_input_field.text = last_player_name;
    5.     name_input_field.ActivateInputField();
    6.     name_input_field.Select();
    7. }
    8.  
    We have also registered to 'onSubmit' so that we leave that screen when the user clicks on Return/Done on the keyboard. That all works fine.

    The problem is, whenever we come back to that screen again, the name input field doesn't get automatically activated/selected like it does the very first time. We've tried to call "ReleaseSelection" or "resetOnDeActivation" with no luck. Any clues why this is happening?

    Thanks!
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Do you get the same behavior in a new simple scene?

    If the behavior is the same in a simple scene, can you provide me with this simple repro scene / project so I can take a look?
     
  3. chico_barnstorm

    chico_barnstorm

    Joined:
    Jun 11, 2014
    Posts:
    10
    Thanks, Stephan! In case it helps anybody, we've fixed it already by doing things in a different order.

    Whenever that screen is activated, we automatically play an 'Appear' anim on it, which modifies some other properties in the name input field's GameObject (e.g. CanvasGroup's Alpha, Block Raycasts and Interactable). For some reason, that was not an issue the first time you visit that screen.

    What we do now, is waiting for the 'Appear' anim to finish to activate the input field. On the last frame of the anim, we have an event that does the activation instead:

    Code (CSharp):
    1. public void activate_input_field()
    2. {
    3.    name_input_field.ActivateInputField();
    4.    name_input_field.Select();
    5. }