Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question How to place cursor in empty TMP input field as though it was clicked.

Discussion in 'UGUI & TextMesh Pro' started by Gordon_G, Dec 29, 2021.

  1. Gordon_G

    Gordon_G

    Joined:
    Jun 4, 2013
    Posts:
    372
    Hey, I'm having try all kinds of methods to give focus to an empty textmesh pro input field to select it so that the user can start typing input immediately, but the place holder text will not get out of the way (if you click in the field the place holder moves above your input):

    upload_2021-12-29_10-55-27.png
    Currently I am using input_field_instance.Select() to produce the above result (after typing of course).

    It seems there is somehow a difference between using that method call and actually clicking in the field.

    So, what is the proper way to select the field programmatically so that it behaves in the same way as if you had clicked on it?

    Thanks for your ideas!

    [Update: I've gotten it to work, but I don't know if this is the best way so I am leaving this open to see if anyone has another method.

    here is how I got it to work:

    first you have to wait a frame using a coroutine, from the frame where the field becomes visible/active.

    then make these two calls on the input field:

    Select();
    ActivateInputField();


    ]
     
    Last edited: Dec 30, 2021