Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
5
Question by judy3turn · May 22, 2016 at 05:50 PM · inputfield

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:" myInputField.Select();

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by neomarian · Nov 28, 2019 at 05:58 PM

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

OR

 yield return new WaitForEndOfFrame();
 InputField.MoveTextEnd(true);

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheGameLearner · Dec 02, 2019 at 05:33 AM 0
Share

Thank you.

avatar image calurin · Feb 29, 2020 at 01:00 AM 0
Share

Brilliant, this works exactly as intended! Only issue is the text selection flash, but $$anonymous$$or detail, and can be hidden with an alpha 0 text selection color. Thanks!

avatar image
2

Answer by SadSwede · Mar 06, 2018 at 05:12 PM

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

 inputField.caretPosition = inputField.text.Length;



Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image TheGameLearner · Sep 24, 2018 at 05:46 AM 0
Share

I just tried it in my code, it didn't work. $$anonymous$$aybe there is some correction, can you repost after taking a look?

avatar image
2

Answer by Zogg · Nov 13, 2019 at 02:30 PM

For TextMeshPro input fields, see https://forum.unity.com/threads/move-cursor-to-end-of-text.530903/#post-3525370

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by JWLewis777 · Dec 10, 2017 at 08:11 PM

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!!!

:(

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ManjuYadav · Mar 30 at 11:25 AM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

62 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Need alternative for onEndEdit on InputField 2 Answers

Access gameobject from a different scene... 1 Answer

How do i convert inputfield input to float ? 0 Answers

Is there a way to set the mass of a gameobject without using the Rigidbody component?? 2 Answers

The UI Button Hitbox changes after using a Input Field on Android 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges