Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

TextMesh Pro TextMesh Pro InputField Incorrect Editing Behavior on Emojis

Discussion in 'UGUI & TextMesh Pro' started by foundway, Nov 8, 2018.

  1. foundway

    foundway

    Joined:
    May 30, 2013
    Posts:
    14
    Hi,

    I am trying default emoji support with unicode in the out-of-box package (with EmojiOne). What I found is that displaying is perfect, but while I use the provided 16 emojis in TMP_InputField. Something unwanted happened when I try to Backspace or Select and Edit.

    To reproduce:
    1. Import TextMesh Pro
    2. Create a new scene
    3. Create a TextMesh Pro - InputField (TMP_InputField)
    4. Type one of the 16 provided emoji (for test purpose, just copy and paste this character: )
    5. The emoji should display correctly at this point
      01.PNG
    6. While Caret is at the end, hit Backspace and it becomes:
      02.PNG
      And we got unstopping errors:
      Assertion failed: TLS Allocator ALLOC_TEMP_THREAD, underlying allocator ALLOC_TEMP_THREAD has unfreed allocations, size 71680
    7. The same thing happen if you hit Delete while caret is at the beginning of the input field.
    Seems like Emoji 6.0 uses two characters in Unity's text field but keyboard operation works only one character at a time. So far I haven't able to find any work around. Anyone runs into the same issue?
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    This is a known issue and something I need to address.

    Most Emojis are mapped in the UTF32 range and require the use of surrogate pairs. So when you delete / use backspace, you end up deleting half of the surrogate pair which is an invalid character and leads to this issue.
     
  3. faleoc

    faleoc

    Joined:
    Aug 13, 2018
    Posts:
    1
    Thanks for your prompt response!

    I plan to try two possible workarounds:
    (1) Process TMP_InputField.text at OnValueChanged to remove the left over invalid character. But problem with this method is that the Assertion failure will probably still happen.
    (2) Use <sprite=xxx> fallback in text and process it at OnValueChanged with REGEX to remove unpaired "<" or ">". This method is probably more reliable than former one.

    Any other ideas? I'll post how the workaround works here when I get to it.
     
  4. iansp

    iansp

    Joined:
    Nov 21, 2016
    Posts:
    5
  5. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Thank for submitting a bug report.

    I just took a look at it and the handling of sprites / emojis which use surrogate pairs has been addressed in the latest version of the TextMesh Pro package which is version 1.4.0. Please upgrade to this latest release.

    Be sure to backup your project first and make sure you close all open scenes before updating TMP via the package manager.

    Below is a video of the new behavior.

    https://imgur.com/RVX6Ts1
     
  6. _Cartman_

    _Cartman_

    Joined:
    May 5, 2016
    Posts:
    6
    Hello, Stephan.
    I have TextMesh Pro package version 2.0.1.
    There is the same problem

    with surrogate pairs of emojis.
    You wrote that this problem was fixed in version 1.4.0. I did all that was described about this problem, no result.
    Could you help please to fix this problem? Maybe there is some secret that I have missed.
    Thank you

    upd. as I understood it may concern the space char between emojis sprites
     
    Last edited: Aug 26, 2019
  7. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    How are you entering the emoji value? Ie. How do I reproduce the behavior you are experiencing in 1.4.1?
     
  8. _Cartman_

    _Cartman_

    Joined:
    May 5, 2016
    Posts:
    6
    I catch OnInputChanged, and, as example, if user enters ":)" I modify it to \U0001F642, that assigned to smile sprite in sprite asset. It works and emoji looks very nice. Then I try to delete it and press backspace. The result is that screen

    In another way, I reproduce it in empry scene. Add TMP_inputField, run scene, copy \U0001F642 to clipboard. The result is fine, emoji looks good. Then try to delete it, press backspace.
     
    Last edited: Aug 27, 2019
  9. _Cartman_

    _Cartman_

    Joined:
    May 5, 2016
    Posts:
    6
    I could fix this problem if I could catch event OnBackspacePressed or something else, and then try to delete surrogate character. Of course, I could handle OnInputChanged, but it would be not trivial to find surrogate char to delete.
     
  10. _Cartman_

    _Cartman_

    Joined:
    May 5, 2016
    Posts:
    6
    I came up with a workaround to fix problem with deleting of symbols from surrogate pair. In OnInputChanged:
    Code (CSharp):
    1. if( _prevInput.Length > input.Length )
    2.         {
    3.             int idxToRemove = -1;
    4.             for( int i = 0; i < input.Length; i++ )
    5.             {
    6.                 var character = input[ i ];
    7.  
    8.                 if( Char.IsSurrogate( character ) )
    9.                 {
    10.                     if( i < input.Length - 1 && Char.IsSurrogatePair( character, input[ i + 1 ] ))
    11.                     {
    12.                         i++;                    
    13.                     }
    14.                     else
    15.                     {
    16.                         idxToRemove = i;
    17.                         break;
    18.                     }
    19.                 }
    20.             }
    21.  
    22.             if( idxToRemove > -1 )
    23.             {
    24.                 input = input.Remove( idxToRemove, 1 );
    25.             }
    26.         }
    But there is a bug with wrong caret position in case of long input string with a lot of emojis after deleting.
     
    Last edited: Aug 27, 2019
  11. mikejichaow

    mikejichaow

    Joined:
    Nov 20, 2012
    Posts:
    9
    is there an official answer to this issue yet? I am running TMP 2.0.1. With "allow rich text editing' unchecked, backspace working fine on PC editor, deleting the emoji on one hit. But in android build, using mobile keyboard, backspace will still delete the ">" and showing the remaining "<sprite=1". Any idea?
     
  12. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    I will try to look into this tomorrow.

    Are you able to reproduce this behavior by simply adding a TMP Input Field in a scene with initial text set to something like "A line of text with a <sprite=0> for testing" and then selecting this input field on the device and editing the text?
     
  13. mikejichaow

    mikejichaow

    Joined:
    Nov 20, 2012
    Posts:
    9
    Yes, and i did some further testing. This issue is actually due to android mobile input. When clicking on TMP inputfield without hide mobile input, native keyboard will bring up the temp inputfield bar and the content from TMP will be copied on there. While emoji will only show the coding i.e. <sprite=1>. backspace press will then delete one char at a time. The rich text sprite check will not work until press "ok" on the temp bar to submit text back to unity. I was previously hacking the mobile input to have my own UI render on top of the mobile input. so i did not see it happend. Now i know is native process blocking it. How can we make this work with mobile input active?

    Further more, i found another bug. Character limit check only work with sprite only or words. If i have some emoji in the inputfield already, adding more words will calculate sprite coding instead of treat emoji as one chat. i.e., setting char limit to 10. Put 2 emojis in: <sprite=0><sprite=1>. if i add another emoji through code like input.text += "<sprite=2", it works, i can add up to 10. But if i select the input and type any char, nothing added as total char is larger than 10 already.
     
  14. djkpA

    djkpA

    Joined:
    Mar 28, 2016
    Posts:
    14
    @mik


    Any solution for the character limit issue ?
     
    xinzhi likes this.
  15. RahmatAli_Noob

    RahmatAli_Noob

    Joined:
    Sep 13, 2022
    Posts:
    70
    Hi there,
    I am using the Emoji's with the Sprite asset and I can use the Emoji's with single Unicode Like "U+1F600" , but there is the Issue that how can I use the Emoji's with the long Unicode Like" u1f3c3_1f3fb_200d_2640" the Running Girl Emoji.
    I try to write it and it shows the Girl but with the Emoji it shows the Boxes.
    Will you please let me know How I can Do it.
    Thanks in Advance.
    @Stephan_B
    @HugoBD-Unity