Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextEditor.pos and TextEditor.selectPos in Unity 5.2

Discussion in 'Scripting' started by Sitalk, Sep 26, 2015.

  1. Sitalk

    Sitalk

    Joined:
    Nov 12, 2013
    Posts:
    30
    Just switched to Unity 5.2 and it seems TextEditor.pos and TextEditor.selectPos changed to something else that I can't find in the documentation.
    There's only a hint somewhere on the internet that they changed them to TextEditor.selectIndex and TextEditor.cursorIndex but it seems they don't work the same way they did before, where can I found some information about what's new with these properties?
     
    Last edited: Sep 26, 2015
  2. djarcas

    djarcas

    Joined:
    Nov 15, 2012
    Posts:
    245
    Any joy? I've run into this too.
     
  3. Sitalk

    Sitalk

    Joined:
    Nov 12, 2013
    Posts:
    30
    Sadly not. For now I'm simply not updating to 5.2 but I'll investigate the issue further.
     
  4. Diab1O

    Diab1O

    Joined:
    Mar 31, 2013
    Posts:
    318
    I have the same problem.
     
  5. Sitalk

    Sitalk

    Joined:
    Nov 12, 2013
    Posts:
    30
    So finally I've got some time to find out whats wrong with these properties.
    Actually selectIndex and cursorIndex work just fine but there's a difference: if your TextEditor is not focused they will return 0! So you've got to manage this.
     
  6. Aldrick

    Aldrick

    Joined:
    Feb 19, 2014
    Posts:
    64
    from 5.1 to 5.2 there is a huge unreasonable change.
     
  7. Pawl

    Pawl

    Joined:
    Jun 23, 2013
    Posts:
    113
    Yep. This sucked.

    Found some luck with the following, but for some reason ended up having to call it twice in consecutive frames to have an effect.

    MoveCaretToEnd would be infinitely better than "MoveTextEnd"

    Code (CSharp):
    1.         //editor.selectPos = cursorPos + 1;
    2.         //editor.pos = cursorPos + 1;
    3.         editor.selectIndex = cursorPos + 1;
    4.         editor.cursorIndex = cursorPos + 1;
    5.         editor.MoveTextEnd();
     
    Weendie-Games likes this.
  8. HamFar

    HamFar

    Joined:
    Nov 16, 2014
    Posts:
    89
    I have the following snippet. From your answers, I cannot figure out how to update my code. Could you help me please?

    TextEditor te = (TextEditor)GUIUtility.GetStateObject(typeof(TextEditor), GUIUtility.keyboardControl);
    te.pos = te.pos-1;
    te.selectPos = te.selectPos-1;
     
    UlalaTopola likes this.
  9. drudiverse

    drudiverse

    Joined:
    May 16, 2013
    Posts:
    218
    thanks pawl. that debugged my old project enough to salvage a code from it.