Search Unity

Text Mesh Pro - The Ultimate Text Solution for Unity - Powerful & Flexible - Advanced Text Rendering

Discussion in 'Assets and Asset Store' started by Stephan-B, May 29, 2014.

Thread Status:
Not open for further replies.
  1. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    First you will need to use one of the TMP Surface shaders as normal text shaders are not designed to take into consideration scene lighting.

    Next, you need to make sure the Canvas Additional Shader Channels are set to TexCoord1, Normal and Tangent.

    I believe the standard UI Shaders are unlit and do not work with scene lighting either. You may have to use a WorldSpace canvas.
     
    boysenberry likes this.
  2. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    150
    hey Stephan - how do i get rid of Zero Width Space ? when i reference my object.text i see that the unicode zero width space is listed in there and im try to check IF null or empty. even if I enter text into the field i see that the zero width space is appended at the end
    thanks!
    daniel
     
  3. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You should be using the TMP_InputField.text property not the .text property of the underlying / child text object.

    This child text object is only used for displaying text and does not contain the valid input field data.
     
  4. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    150
    pretty sure i am :
    [SerializeField] public TextMeshProUGUI keeper1nametext;

    then i have:

    Debug.Log("%" + keeper1nametext.text + "%");

    output which has unicode in it:

    %%
     
  5. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    150
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You need to reference the TMP_InputField and not the child TextMeshProUGUI object. For instance when displaying a password, the child TextMeshProUGUI object would contain "*******" whereas the TMP_InputField.text would contain the actual and correct password.

    Add the script below to some object. Make sure you assign the TMP_InputField in the public field. Reference it as per the image in the On Value Changed

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using TMPro;
    6. public class Sandbox_01 : MonoBehaviour {
    7.     public TMP_InputField TextInputField;
    8.     public void OnTextChanged()
    9.     {
    10.         Debug.Log(TextInputField.text + "   " + TextInputField.text.Length);
    11.     }
    12. }
    13.  
    upload_2018-1-25_15-51-15.png
     
    Last edited: Jan 25, 2018
  7. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    150
    i get what you are saying now -

    [SerializeField] public TextMeshProUGUI keeper1nametext;
    needs to be

    [SerializeField] public TMP_InputField keeper1nametext;
     
  8. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    150
    bingo that fixed it - haha thanks Stephan sorry i misunderstood!
     
    Stephan_B likes this.
  9. boysenberry

    boysenberry

    Joined:
    Jul 28, 2014
    Posts:
    365
    Super useful, thank you!
     
  10. basssssss

    basssssss

    Joined:
    Jan 24, 2013
    Posts:
    6
    Hi guys. Great plugin, only problem I have is when i try to generate Sprite Assets. They've got these weird offsets when i generate them. Even when I try to generate a Sprite Assets from the'DropCap Numbers' example spritesheet.

    This is what it looks like:

    http://prntscr.com/i7j24i

    You guys got any idea what i'm doing wrong?
     
  11. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    797
    You can control/adjust the offsets in the Sprite Asset under "Sprite List". Covered in this video
     
    Stephan_B likes this.
  12. basssssss

    basssssss

    Joined:
    Jan 24, 2013
    Posts:
    6
    Thanks! So I am supposed to set them manually? I maybe thought this was a bug and hoped the process could be almost automatically. Bummer!
     
  13. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    797
    You can try adjusting the global offsets for the whole sprite asset (it's all in the video). If your sprites are all the same size, this would probably work fine. Almost automatic ;)
     
    Last edited: Jan 31, 2018
    Stephan_B likes this.
  14. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The pivot of the sprites will be aligned at the baseline of the text and advance of previous character. So when you define the sprites you can make this automatic.
     
    tosiabunio and hopeful like this.
  15. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    508
    Hi @Stephan-B ,

    Hope you’re fine.

    Some time, some textmesh pro disappear from the screen (on iPhone X especially).

    Did you already seen/did ear something about it ?

    Any idea ?

    I don’t have any error ... it just happens.

    We have 10M daily user ... fortunately, it’s just the iPhone X.

    Thanks a lot!

    Best regards,

    Anthony B
    Pangolapp
     
  16. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Saw your post on the TMP user forum. Already answered that I will need more information with regards to if it is all font asset that do not appear or just some of them. If just some of them, let's see if you can find some settings like possibly texture size, padding, Clip Rect ranges that could be resulting in this behavior.
     
  17. Deleted User

    Deleted User

    Guest

    Excuse me,I also get the issue,have you fixed it yet?
     
  18. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This RectTransform issue has been fixed in the latest patch for Unity 2017.3. I also believe it has been fixed in the latest 2018.1 beta as well.
     
  19. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You mean some type of deformation of the geometry of the text object?

    If so, it is possible as the geometry of the text object can be modified. See examples included with TextMesh Pro like example 23 - Animating Vertex Attributes as well as look at the example script called WarpTextExample.cs.

    Please keep in mind that the geometry of each character is made up of just 4 vertices and as such will limit how much deformation you can apply without having to tessellate the geometry.

    There are tools like Mega-fiers which can do that. See an example here.
     
  20. hgrayvivox

    hgrayvivox

    Joined:
    Mar 3, 2017
    Posts:
    15
    Hey Stephan, having a weird issue with unicode in input text fields. I saw a few posts which seemed semi-similar but didn't have a resolution.

    Repro 1:
    - Unity 2017.1.f3
    - New project
    - Import TMP (TextMeshPro-2017.1-1.0.56-)
    - Add a TMP input box
    - run and enter a unicode symbol. I've been using although I've had various results with other unicode. The smiley seems to be less likely to cause issues
    - now backspace to delete one of them

    Result:
    - For each symbol, the first backspace removes the sprite but adds in the blank space (square) glyph
    - On second backspace, the square is removed

    Desired:
    - One backspace removes the symbol and moves the caret back one space

    Repro 2:
    - Same as above, but disable Rich Text Editing

    Result:
    - First deletion puts the square glyph somewhere in the text, but not where the caret position was
    - A series of logs and errors which won't stop until Unity is restarted
    • Allocation of 2048 bytes at 13400010
    • Assertion failed: TLS Allocator ALLOC_TEMP_THREAD, underlying allocator ALLOC_TEMP_THREAD has unfreed allocations
    Thanks!
    Hardin
     
  21. Lividus

    Lividus

    Joined:
    Apr 20, 2015
    Posts:
    3
    I try to use free version from asset store, but

    IndexOutOfRangeException: Array index is out of range.
    TMPro.TMP_Text.ValidateHtmlTag (System.Int32[] chars, Int32 startIndex, System.Int32& endIndex)
    TMPro.TextMeshProUGUI.GenerateTextMesh ()
    TMPro.TextMeshProUGUI.OnPreRenderCanvas ()
    TMPro.TextMeshProUGUI.Rebuild (CanvasUpdate update)
    UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/CanvasUpdateRegistry.cs:150)
    UnityEngine.Canvas:SendWillRenderCanvases()

    when i add <link> tag to text
     
  22. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I'll need more information.

    Can you provide me with the exact text used that produced this error?

    Most likely, the link tag ID that you used was too long. The format for the link tag is <link="ID">Descriptive text</link> This ID is not a url. This ID allows you to identify which link was interacted with so you can then implement any logic to act on the link.

    See Example 12a included with TextMesh Pro and look at the EventHandler and scripts used as it also shows how you can track character, word, line and link interactions.
     
  23. Lividus

    Lividus

    Joined:
    Apr 20, 2015
    Posts:
    3
    To reproduce the issue:
    In Unity 2017.3.0f3 i create empty scene, add Canvas and create TextMeshPro Text from the context menu.
    Then i copypaste this string:
    "Приложение создано в <style="Link"><link="id_01">Балабла</link></style> использует технологии <style="Link"><link="id_02">Балабла</link></style>."
    into the "Text input box" into TextMeshPro UGUI component. And then got the error.

    In the exemple scene "12 - Link Example" everything works correctly.
     
  24. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Taking a look now. Will provide feedback as soon as I have more information.

    The example was "12a" which is different than example 12.

    UPDATE
    The reason you are getting this error is because the <style="Link"> which is used in one of the examples, already includes <link="ID_01"> and as such you are essentially nesting links which results in that error.

    If you take a look at the Default Style Sheet and at this link tag, you will see the definition for the opening and closing tags. The Link style should have probably just been a visual style where it only adds the underline and color but not a specific link ID.

    Although having nested links doesn't make sense, I will still revised the handling as producing an error isn't good either.

    UPDATE 2
    I revised the handling in the event someone unintentionally ends up using nested links. When this happens, the last nested link ends up being the one that is used. So in the case of your example text, it still results in the correct behavior without errors.

    upload_2018-3-8_15-8-53.png
     
    Last edited: Mar 8, 2018
  25. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    First my apologies for the delay response. Unfortunately, the forum doesn't always notify me of new posts and given the thread is super long, it is pretty easy for any given post to get swallowed up.

    As we go forward and to minimize the potential of any posts being overlooked, please post in the Unity UI & TextMesh Pro section of the forum. Be sure to add the Prefix for TextMesh Pro. Since these posts / threads will be separate from each other, this will also make it easier for other users to find / search thru these posts.

    Furthermore, if a post ever goes for more than 24 to 48 hours before getting a reply, always feel free to reply / tag your post as a reminder.

    In terms of your question / feedback, the behavior is the result of some of those unicode characters being UTF32 where they are made up of a high and low surrogate pair. Since these are made up of two characters, using backspace ends up deleting half of the pair which is wrong and ultimately leads to these errors.

    This is a behavior that I need to address. I'll try to get to it in the next week or so.
     
  26. hgrayvivox

    hgrayvivox

    Joined:
    Mar 3, 2017
    Posts:
    15
    Thanks very much Stephan. Also thanks for the note on where to post. I'll keep that in mind for the future.
     
  27. Trivium_Dev

    Trivium_Dev

    Joined:
    Aug 1, 2017
    Posts:
    78
    Hi Stephan,

    Is there a way to get the actual width of the visible text when using "auto size" and "wrapping & overflow" are set to "Disabled" and "Truncate"? I need to manually place a cursor at the end of the text within the TextMeshProUGUI field, and auto-size the font size down if the text gets too long. Currently using
    LayoutUtility.GetPreferredWidth(this.myTMPUGUIObject.rectTransform) and that works well until the text gets too long and the TMProUGUI starts auto-sizing the font size to make it smaller.

    I feel like this should be relatively easy and I'm just missing the functionality to get the width of the text.

    Thanks!
     
  28. Neo-Dragon

    Neo-Dragon

    Joined:
    Feb 29, 2016
    Posts:
    17
    Hi Stephan,
    Sorry to post again asking about the same issue but has the rect transform prefab issue been patched?
    I'm using the Unity 2017.3.1f1 and latest TMPro that was posted recently and I still get text getting offset once I hit the apply button on the prefab.
    Example (should be centered):
    https://i.imgur.com/p4IMrI0.png
     
  29. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Most of the RectTransform issues were addressed in the patches for 2017.3.1.

    You will need to get the latest patch which is Unity 2017.3.1p3.
     
  30. skyrusfxg

    skyrusfxg

    Joined:
    Jan 14, 2016
    Posts:
    127
    Hello. I have TMT_Settings with fallback font assets upload_2018-3-16_6-13-55.png

    The task is to check wether each char exists in font asset and fallback assets or not (in input text process). And if it not exists, the char should be not allowed for input. I am checking fallback fonts this way:
    upload_2018-3-16_6-21-38.png
    How properly to check it in runtime?
     
  31. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You can use public bool HasCharacter(char character, bool searchFallbacks)

    This will search the font asset on which you are calling this function but also go through its fallbacks as well as TMP Settings fallbacks list.

    Currently, this requires the font asset you are search have been loaded which should not be a problem if that is the font asset to the object you are searching.

    If you are searching a font asset that hasn't been loaded this will return false but I will address that in the next release. If you run into this scenario, you can call ReadFontDefinition() on that font asset first.

    Currently the HasCharacter() doesn't search recursively through the fallbacks of the fallbacks themselves but I will also address this behavior.
     
  32. Cleverlie

    Cleverlie

    Joined:
    Dec 23, 2013
    Posts:
    219
    hi @Stephan_B I'm having a problem with a text, I'm creating a world space canvas, in this canvas I have a description box which is a scrollview, this description box is a copy paste of a description box I did for another 2d screenspace canvas, the problem is that the textMeshProUGUI text is not masking in the worldspace canvas, I tested with a normal unity text object and it masks correctly but TMP doesn't, I'm using the Mask component, not the 2DMaskRect component.

    can you help me with this? is this a bug or is it expected?

    below you can see the white ugly unity text masking correctly while the tmp text is not.
    problem.jpg
     
  33. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    This is an issue with the Stencil Masking where the public API from Unity didn't allow me to handle this correctly in the past. If I have time this might be something that I will fix at some point.

    Having said that and the reason I have not rushed to fix this is because you can replace the UI.Mask by the more efficient 2D RectMask and everything should work as expected. The 2D RectMask also supports soft masking which is an additional bonus.

    When replacing the UI.Mask by a 2D RectMask, you can typically remove the UI.Image and CanvasRenderer as those are not needed with the 2D RectMask.

    Let me know if this works as expected for you.
     
    Last edited: Mar 16, 2018
  34. Cleverlie

    Cleverlie

    Joined:
    Dec 23, 2013
    Posts:
    219

    effectively, the 2DRectMask works like a charm, I didn't use it before because I assumed it will only work in 2D UI's o_O

    so how is that this mask can do soft masking? I don't see any options in the component.

    thanks!
     
  35. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The options are on the material in the debug section of the material inspector. Also look at Example 19.
     
    Cleverlie likes this.
  36. Yerendi

    Yerendi

    Joined:
    Mar 11, 2016
    Posts:
    18
    Hi,
    I'm using TMP on my game chat. To reduce spike when message comes I don't use any layout (vertical, horizontal, fitters etc). I have 30 TMP UI Text components and on every message I rewrite messages upwards. But on every mesage TMP creates it's own mesh over and over again. Is it possible to cache this mesh and moves only mesh without regenerating it each time? It's taking like 95% performance on my chat (8ms each message).
     
  37. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Whenever the content of the text or a property of the text is changed, the text has to be regenerated.

    If I understand correctly, once the first message is typed, you shift the content from one text object to another and you have about 30 of those vertically? Is that correct?

    Are you re-assigning the text from the previous to the next up in the chain?

    How much text is in each of those box? 8 ms per box seems like a lot unless you are using deep profiling which isn't accurate in regards to time but accurate in terms of how much something takes relative to something else.

    You could also move these box up / scroll instead of copying the content from one to the other.

    Have you looks at Example 20 included with TMP which includes a simple chat box? The alignment of the Content object could be wrong where it should be for 5, 5, 5, 5 for Left, Top, Right and Bottom. How is that in terms of performance?
     
    Last edited: Mar 21, 2018
    Yerendi likes this.
  38. Yerendi

    Yerendi

    Joined:
    Mar 11, 2016
    Posts:
    18
    Ok, now its working with only 0.2ms! I'm moving text components up when message comes - I've did it before but with using layouts and perfo was terrible. Now, following your advice I've made in once again but without layouts and its working great, thanks!
     
  39. Yerendi

    Yerendi

    Joined:
    Mar 11, 2016
    Posts:
    18
    Ok, so next question - in Unity UI Text component I can get:

    Text.font.GetCharacterInfo(char, out CharacterInfo, fontSize);
    /I need to call RequestCharactersInTexture first but it does not matter now/

    How can I access a glyph's width in TMP?
     
  40. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Whenever a text object is generated, the TMP_Text.textInfo gets populated. This textInfo contains several sub structures which includes information about every character, word, line, links, etc. even the geometry.

    In this case, you want to look at the textInfo.characterInfo[index] which contains the relevant data about each character.

    There are several posts about this topic on the TMP user forum.

    You can also add to any TMP objects the "TMP_TextInfoDebugTool.cs" script which is included with the examples.This script will allow you to visualize the information in the textInfo. I use that for debugging. This is also a good source of learning how I access this information.
     
    Yerendi likes this.
  41. Yerendi

    Yerendi

    Joined:
    Mar 11, 2016
    Posts:
    18
    Thanks Stephan.
    So, if anyone is curious, here you have solution for getting single character size by giving font size (you don't need to fill text component with text to do this).

    Code (csharp):
    1. charSize =
    2. m_TextComponent.font.characterDictionary[character].width * ((m_TextComponent.fontSize+m_TextComponent.font.fontInfo.Padding/2) / m_TextComponent.font.fontInfo.PointSize);
     
    Last edited: Mar 23, 2018
  42. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    I found a bug, I'm not sure if you've fixed it already but here's the code

    TMP_Private.cs: Line 167

    Code (csharp):
    1.  
    2.  // Check to make sure Sub Text Objects are tracked correctly in the event a Prefab is used.
    3.             TMP_SubMesh[] subTextObjects = GetComponentsInChildren<TMP_SubMesh>();
    4.             if (subTextObjects.Length > 0)
    5.             {
    6.                 for (int i = 0; i < subTextObjects.Length; i++)
    7.                     m_subTextObjects[i + 1] = subTextObjects[i];
    8.             }
    9.  
    The for loop condition should probably be

    Code (csharp):
    1.  
    2. i < subTextObjects.Length-1;
    3.  
    I get an out of range exception when using multiple icon materials.
     
  43. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I will most certainly review this.

    How many materials / sub objects do you end up using? Just looking for more insight on reproducing the conditions for the error.
     
  44. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    I had 4 on there. But looking at the comment above that loop it seems to have to do with prefabbing and then instancing something using multiple sub renderers.
     
  45. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    It is related to Prefabs in the sense that during serialization / deserialization some of the data is not persistent.

    I have been trying to reproduce the behavior with a varying number of sub objects and prefabs but can't reproduce it right now. In theory the internal m_subTextObjects[] should always be larger than the subTextObjects.

    This is where I repro scene / project would be useful in tracking down what may lead to the out of range index.
     
  46. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Oh I see, I think i had some code that added a whole bunch of icons by mistake and I realised there were more than 8 (the array max size for m_subTextObjects). That's probably what the issue was. It should probably fail a little more gracefully though.

    I just reproduced it, duplicate a subMesh a bunch, apply, delete and then drag it back into the scene.

    Screen Shot 2018-03-29 at 9.36.48 AM.png
     
  47. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Are you duplicating these SubMesh using Copy / Paste? SubMeshes are created as a result of the content of the text and text object needing them. These should not be created manually.

    And if you are creating those manually and out of curiosity, why are you doing that and what is the use case?
     
  48. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    No I'm not usually doing it manually. I had some editor code that added a bunch of icons to a string that resulted in a bunch of subMeshes, i then prefabbed it and the but resulted.

    Copying them manually is just an easy way to reproduce the bug.

    However if you are curious, I do find it useful to have them created in a prefab so i can change the material on them, to fix ordering issues, make them grey scale, and other effects like that. I should probably build some fancy system to do that but doing it this way is good enough for now.
     
  49. Deleted User

    Deleted User

    Guest

    When I repack the spriteAsset by TMP Sprite Inporter,all the TMP_UGUI spriteAsset in my prefab missed which refenerce to it.
     
  50. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The Sprite Asset Importer created a new sprite asset so its GUID and FileID would be different than the previous one which is why the prefab who uses the GUID and FileID of asset would loose those references.
     
Thread Status:
Not open for further replies.