Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Textmeshpro Caret Position Change

Discussion in 'Unity UI & TextMesh Pro' started by SAJID_Playsimple, Apr 10, 2018.

  1. SAJID_Playsimple


    Apr 10, 2018
    i'm trying to move caret in textmeshpro inputfeild To A Certain Position In A String of 10 letters
    but it is not working for some reason i've used the latest version of textmeshpro

    I've logged the position and it is accurate but visually the cursor stays at the same place
    can anyone help me on how to move caret in inputeild manually via script

    public TMP_InputField MessageInputField;
    void SomeFuntion(){
    MessageInputField.caretPosition = MessageInputField.text - 5;
  2. PSchaussPlaya


    Mar 2, 2018
    Did you find any solution by now?

    I have the same problem with Unity 2018.1.0f2 and TMP 1.2.2 from the package system.
    Setting caretPosition does not seem to have any impact on the caret position.
  3. PSchaussPlaya


    Mar 2, 2018
  4. troien


    Jan 15, 2013
    I managed to get something like this to work. Although it is a workaround...

    I wanted to make another UI item (which is linked to a part of the text) to select the correct piece of text when I hover the other UI item.

    Something like this is what I ended up using on that other UI item.

    Code (CSharp):
    1. public class ExampleClass : Selectable, IPointerEnterHandler, IPointerExitHandler
    2. {
    3.     [SerializeField]
    4.     private TMP_InputField field;
    6.     public override void OnPointerEnter(PointerEventData eventData)
    7.     {
    8.         field.selectionAnchorPosition = 1; // your caret start position here
    9.         field.selectionFocusPosition = 4; // your caret end position here
    10.         field.Select();
    11.         this.Select();
    12.     }
    14.     public override void OnPointerExit(PointerEventData eventData)
    15.     {
    16.         field.selectionAnchorPosition = field.selectionFocusPosition;
    17.         field.Select();
    18.         this.Select();
    19.     }
    20. }
    I don't know whether this will work for you because you have a different setup. But when I added the 2 selects, it started to work as intended. So I think this might work for you aswell, provided you have something else to select.