Search Unity

Inserting Rich Text and Caret position

Discussion in 'UGUI & TextMesh Pro' started by Chimooo, Jun 26, 2019.

  1. Chimooo

    Chimooo

    Joined:
    Oct 23, 2015
    Posts:
    4
    I am inserting rich text in the input field as the player is typing. The following used to work:
    1 - Save the caretPosition.
    2 - Update the input field with the rich text.
    3 - inputField.textComponent.ForceMeshUpdate();
    4 - inputField.caretPosition = prevcaretPos;

    But now forceMeshUpdate seems to do nothing and the caret position, is at the position n from the start of the rich text tag where n is the number of characters of word being tagged.
    For example:
    text field contains: word (caret position is after d)
    when player hits space
    I insert <color=#ffffff>word</color>
    the result is : <col or=#ffffff>word with the caret position after the the space after <col

    I am not sure how the caret position is calculated anymore. Or how can I get around this issue.
    Thanks!
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    What version of the TMP package are you using?


    There is / was an issue with ForceMeshUpdate(). Not sure if this is the source of your current issue but here is the revised function which is contained in the TextMeshProUGUI.cs script.

    Code (csharp):
    1.  
    2. /// <summary>
    3. /// Function to force regeneration of the text object before its normal process time. This is useful when changes to the text object properties need to be applied immediately.
    4. /// </summary>
    5. /// <param name="ignoreActiveState">Ignore Active State of text objects. Inactive objects are ignored by default.</param>
    6. /// <param name="forceTextReparsing">Force re-parsing of the text.</param>
    7. public override void ForceMeshUpdate(bool ignoreActiveState = false, bool forceTextReparsing = false)
    8. {
    9.        m_havePropertiesChanged = true;
    10.        m_ignoreActiveState = ignoreActiveState;
    11.        m_isInputParsingRequired = m_isInputParsingRequired ? true : forceTextReparsing;
    12.        OnPreRenderCanvas();
    13. }
    14.  
    If this doesn't resolve the issue, please provide me with a simple scene / project that will enable me to reproduce the issue. The easiest way to provide this to me is to submit a bug report and provide me with the case # once you have it.
     
  3. Chimooo

    Chimooo

    Joined:
    Oct 23, 2015
    Posts:
    4
    I have tried to create a new project to replicate the issue and it worked fine there... So I uninstalled and reinstalled TextMeshPro on my project which was already 2.0.1 and now it works fine again.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Glad to hear it is working as expected now.

    Be sure to let me know if you ever run into that behavior again.