Search Unity

TextMesh Pro How to make a TMP_InputField automatically be in editing mode?

Discussion in 'UGUI & TextMesh Pro' started by Yandalf, Feb 15, 2020.

  1. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Hey everyone!

    I'm making a system where a popup can appear with an InputField, and I'd love for users to simply be able to begin typing without having to click or hit enter first.
    I figured out that when I enable the object, I could simply call Select on the Field to make it the currently selected element, but this doesn't make it start input/edit mode unfortunately. I then did some more digging and tried things like calling ActivateInputField, calling Select a second time after calling ActivateInputField, and even tried to send a fake "enter" event with ProcessEvent and giving it a new Event with KeyCode.Return. I also tried calling ForceLabelUpdate.
    None of these attempts seemed to do anything unfortunately, when the object is activated users still first need to hit enter or click the input field to begin editing text.
    How do you do this?
     
  2. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    So after a few more tries it turns out I can do this by first calling ActivateInputField, waiting a frame, and then calling Select. It doesn't seem to work if I do this within the same frame.
     
  3. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    I believe I've done this with

    inputField.OnPointerClick(new PointerEventData(EventSystem.current));


    (using UnityEngine.EventSystems)