After adding text to an input field, I want focus to set the caret to the end

I have an input field that I want to automatically fill in parts of based on the user’s clicking on a set of toggles. I then want to set the focus to that input field and have the cursor at the end of the automatically filled in text so the player can add personalized text.

I currently have:
myInputField.text = “text I want to add:”

This results in the input field hilighting the text I added so if the player just types away it will overwrite the automatic text.

How do I get the new text NOT hilighted and the cursor at the end of the text. It seems like there should be a “Get end of text line cursor position” or something but I haven’t found it and all I can find is how to align the cursor with the pivot so it lines up correctly vertically.

Just incase people come across here like i did, here is the solution:

inputField.caretPosition = inputField.text.Length;

For TextMeshPro input fields, see

yield return new WaitForEndOfFrame();
InputField.caretPosition = InputField.text.Length;

yield return new WaitForEndOfFrame();

put this in an IEnumerator function or remove the yield statement and call this in LateUpdate()

Even though this is an old post, I am reviving it because this is still an issue.

I have been going through this for hours now, trying everything I can find.

If you use any kind of code to set focus on the inputbox the existing text will get highlighted.

I had to turn the highlight alpha to 0 to hide it, then position the cursor to the end of the text in the update method.

In the end, the cursor would jump to the middle of the inputbox even though the cursor position number was showing the correct number in the editor. I finally gave up on the inputfield as a horribly bugged POS.

I am now working on making my own inputfield for the same reason I had to create my own custom virtual keyboard, buggggggssss!!!


In TextMeshPro - Inputfield —> Control settingsOnFocus Select All (should be disabled).
This is available only in TextMeshPro.

1 Like