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 23, 2011
    Posts:
    2,269
    The "Fast but no exception" issue was addressed a few betas ago. Basically, Unity cannot call Constructors or Field Initializers from threads other than the main. When "Fast but no exception" is used, some of the code is executed in the loading thread (controlled by Unity) which was causing the issue. It is a Unity issue but I was able to handle getting those property ID's in some other fashion.

    In terms of the slow down, let me know if that makes any difference. Instantiating new objects at run-time (regardless of the object) can have a big impact on performance and there are tricks to minimize that. Just reach out to me if you still have performance issues.

    With regards to the latest beta of TextMesh Pro, a few changes are worth noting in updating in an existing project. There is a new Text Container which will require potentially adjusting alignment since that has changed. The FaceColor property has changed from Color32 to Color to make it work with Unity's Animation Editor. However as a result of the change, FaceColor values will be lost in the conversion. Just keep those things in mind.

    To get access to the latest beta, you will need to register to the TextMesh Pro User Forum if you haven't done so already. Then just send me a PM here or on the TextMesh Pro User Forum asking for access to the Beta.
     
  2. Everclyr

    Everclyr

    Joined:
    Jul 24, 2014
    Posts:
    2
    Beautiful Thank you! I will ensure I'm signed up!
     
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    Hi,

    I bought TMP 0.1.44 recently and it's doing a good job so far. Thanks for the work you put into it! :) However, some of the source files emit warnings, which I would like to see fixed in a future version, if you don't mind. I use Unity 4.6 beta on Windows 8, with target platform set to PC, Mac & Linux Standalone.

    TextMesh Pro\Scripts\TMPro_AdvancedLayout.cs
    Code (CSharp):
    1. Field 'TMPro.TMPro_AdvancedLayout.isRedrawRequired' is never assigned to, and will always have its default value false, Line 26
    2. The field 'TMPro.TMPro_AdvancedLayout.m_meshFilter' is never used, Line 36
    3. The field 'TMPro.TMPro_AdvancedLayout.m_mesh' is never used, Line 38

    TextMesh Pro\Scripts\TextMeshProFont.cs
    Code (CSharp):
    1. The field 'TMPro.TextMeshProFont.m_kerningPair' is never used, Line 50

    TextMesh Pro\Scripts\TMPro_Private.cs
    Code (CSharp):
    1. The field 'TMPro.TextMeshPro.m_selectedFontAsset' is never used, Line 213
    2. The field 'TMPro.TextMeshPro.m_StopWatch' is never used, Line 243
     
  4. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    There should be a few more and those are only warnings so they don't affect anything. Once I get closer to release (ie. out of beta) I will be sure to run through all of it to clean up left over debug and experimental code to make all those warnings go away :)
     
  5. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Font Asset Padding
    When creating an SDF Font Asset in TextMesh Pro, the padding determines the spread on the distance field. The spread affects the range of most property like Dilation, Outline, Underlay, Glow, etc...

    Typically a padding value of 5 for a 512 X 512 Font Asset is fine for most use. However, there may be times where you need extra range on Glow or Shadows for instance. In these cases, you can increase the padding size. Here is an example of a Font Asset where the padding was increased from 5 to 12.



    Increasing the padding size will result in a smaller sampling point size for the font which means it won't be as accurate as a larger font. This can be a marginal thing depending on the font. Larger padding size will result in the computation of the Signed Distance Field asset taking potentially a lot more time to compute. A padding of 5 in a 512 X 512 is the same as padding of 10 in a 1024 X 1024 Font Asset.
     
  6. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
    Textmesh pro support ngui?
     
  7. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I do have several users using it as a replacement for NGUI's text label.

    There are a few threads on the TextMesh Pro user forum as well as posts in the TextMesh Pro WIP and Asset Store thread here about NGUI and TextMesh Pro.

    So far so good as they say. :)

    Should you require any assistance please feel free to reach out to me.
     
  8. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Just a variation on the above text with added texture, bevel and glow + UV animation

     
  9. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    Unity 4.6 will be done soon I hope since we are on 4.6 RC3 already. Can't wait for all of the new features in this tool
     
  10. imaleper

    imaleper

    Joined:
    Nov 14, 2012
    Posts:
    30
    Hey man,

    Great product!

    I want my tween my texts alpha, whereby I might have multiple color tags in the text but one main global <a =1.0></a> surrounding the whole lot. How might I go about doing this? So that I do not need to keep updating the string in multiple locations in realtime via script?

    Specifically I am using the distance field mobile with outline and underlay, each color with different alphas but should all be controlled by a main component based tag. Could it be done with vertex colour?

    Thanks

    *Edit: I notice you were considering such an approach earlier however you opted to go for appending the alpha to the end of the color tags
     
    Last edited: Nov 25, 2014
  11. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Changing the TextMeshPro.color which in the current version is a Color32 property and tweening its alpha will allow you to get the result you want.

    Code (csharp):
    1.  
    2. // The color property will change the vertex color.
    3. m_TextMeshPro.color = new Color32 (255, 255, 255, alpha);
    4.  
     
  12. imaleper

    imaleper

    Joined:
    Nov 14, 2012
    Posts:
    30
    Perfect, thank you.
     
  13. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Let me know if you need any adfitional help on this
     
  14. imaleper

    imaleper

    Joined:
    Nov 14, 2012
    Posts:
    30
    I've actually come across a problem of a missing "W" glyph when I run these characters through the font generator (SDF16) "!¡"#$£€%&+,-.?¿`|©×™_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzÀÁÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ"

    The font I'm using is Impact. And it's weird because it seems to show up for hinted smooth, but leaves out some others (manifesting in empty rectangles), could there be some unicode clashes or something of that sort?
     
  15. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I am aware of an issue where Unity requires UTF8 encoding with text assets which is what is used.

    My recommendation is to add all those character into a text file and chose UTF8 encoding on saving and then use Characters from file in the font asset creator.

    I am pretty sure the encoding is UTF8 but it is an encoding issue for certain and saving using different encoding solves it.
     
  16. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It may be reasonable for you to load and save the string as UTF8 within TextMesh Pro, as it might be something people would have to search this forum for to understand, and it may get missed entirely when people use translations.

    ie something like

    byte[] bytes =Encoding.Default.GetBytes(myString);
    myString =Encoding.UTF8.GetString(bytes);
     
  17. imaleper

    imaleper

    Joined:
    Nov 14, 2012
    Posts:
    30
    Thanks men.

    I'm now trying to implement auto text sizing but can't seem to find either the Text Container class or the "auto" checkbox on the TextMeshPro component.

    What am I doing wrong?

    *Edit

    Sorry, I now realise that this is a 4.6 only feature, and was working on the beta only... Now that 4.6 is out, do you think it will take long to release the alpha?
     
    Last edited: Nov 26, 2014
  18. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I am trying to get the next release out but until then, you can access the latest beta of TextMesh Pro which includes the auto sizing feature and all from the TextMesh Pro User forum. You just need to register and then send me a PM with your username and I will get you access.
     
  19. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Maybe I am missing something here.

    When you create a simple text file in Notepad and save it. The default encoding format is ANSI. So as soon as it is imported in Unity and selected using EditorGUILayout.ObjectField the Unity TextImporter will try to parse it as UTF8 and if it is not in that format, it will strip the non ASCII characters. So by the time I get to read the file which was selected in the ObjectField, the non ascii characters are gone.
     
    Last edited: Nov 27, 2014
  20. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Aha, so it's actually Unity which is doing the bad stuff. You'd need to log it as a bug I think, or behaviour that needs to be optional. I'd have thought pulling the bytes out of it would be enough.
     
  21. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I wasn't sure either at first but the docs on the TextAsset.bytes kind of point to what is going on. I'll log it and hope it gets some love soon.
     
  22. imaleper

    imaleper

    Joined:
    Nov 14, 2012
    Posts:
    30
    MonoDevelop - New File>Misc.>Empty Text File, and Save As into any encoding you want. Thanks for the support, I'm not in a rush to get this feature in, glad to hear it's coming down the line. Thanks
     
  23. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Yeah it's just that people have to do that step, and possibly more often than they realise or notice. For a shipping title and translations, it's worrying. You know how these things slip through. I'd argue its not really Stephans responsibility, but it's the hallmark of a great asset that goes that extra mile.
     
  24. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The challenge with this encoding issue is that by the time the user imports the file into Unity, Unity has already stripped the non ASCII characters without their knowledge unless they happen to use the UTF8 encoding.

    The options are to (a) Get Unity to address this so they don't strip non ascii characters from files which is the best solution or (b) see if there is a way to use the assetimporter to intercept the import and stop Unity from stripping those characters out.
     
  25. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I did some additional digging into the encoding formats and basically ANSI is limited to 255 characters which makes it unable to handle most international languages. It is sort of a bummer that some applications default to that format or don't even warn you when the characters you are trying to save won't even be preserved.

    I tested Unicode and UTF8 formats and those work fine so when generating a Font Asset using "Characters from File" either Unicode or UTF8 should be used.

    It turns out this isn't really a Unity thing either but an encoding limitation on the file itself when it is created and saved.
     
  26. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
  27. TechnicalArtist

    TechnicalArtist

    Joined:
    Jul 9, 2012
    Posts:
    736
    Thanks for the reply, but now I have switched to Unity 4.6 and new UI system available in it. So no more NGUI required.
     
  28. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Yes. You can import any TTF or OpenType fonts into Unity and then using the Font Asset Creator create your font asset using Distance Field 16 or 32.

    Here is a link to some videos which explains this process.
     
  29. mulova

    mulova

    Joined:
    Apr 14, 2011
    Posts:
    62
    Can I select custom character set when creating font asset from TTF?
    Because CJK font contains a large number of characters, I need to select subset of characters.
     
  30. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Hey Stephan!
    I have been enjoying TextMesh pro quite a bit! I have a question though, I can access facecolor, textmesh color and outline color through code, but I cant find a way to access the glow color, is there a way to do this?
     
  31. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    With the Font Asset Creator, you have different options like Custom Range(s), Custom Characters or Characters from File where the characters you want to include are contained in the text file saved with Unicode or UTF8 encoding.

    Here is a link to some videos explaining the process and options.
     
  32. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    To alter the glow color or power, you have to go modify the material property directly.

    For Glow Color the property is "_GlowColor" and for Glow Power it is "_GlowPower" ... there is also a utility class ShaderUtilities which has property ids for all of those properties. Access material properties via the ID is more efficient than by name.

    When changing material properties, the change is immediate as opposed to processed once per frame at the end of the frame. So if you were to change the glow color and then assign a new material, the new material would override the change which you just made to glow color. If you run into any issues doing this, just reach out to me.

    P.S. Be sure to register to the TextMesh Pro User Forum
     
  33. JakeTBear

    JakeTBear

    Joined:
    Feb 15, 2014
    Posts:
    123
    Thanks, it worked pretty well :)!
     
  34. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Do you know if there are any upcoming text improvements planned for Unity 4.6? Because text doesn't seem to be handled too well right now by the new UI in terms of sizing, sharpness and performance.

    If so, will your asset still have any advantages over any text solution offered by Unity? Thank you
     
  35. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Registered users can get the latest beta releases of TextMesg Pro with support for Unity 4.6 on the TextMesh Pro user forum. There should be a new release later tonight.

    There are certainly definite advantages with TextMesh pro over the unity 4.6 text in terms of rendering quality and layout / control options
     
  36. lightningGamer

    lightningGamer

    Joined:
    Feb 19, 2013
    Posts:
    52
    I am having some real problems with Unity 4.6's text on mobile devices. Whenever I update the text, which only happens once/twice a second it occasionally causes lag spikes. Does Text Mesh Pro update text more efficiently than the current unity system does?
     
  37. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    TextMesh Pro only updates when a change is made that requires and update.

    Now in terms of Unity 4.6, Unity tries to reduce the drawcalls and batch all the elements of a Canvas and that can result in additional processing resulting in lag spikes.

    For instance, assuming you have 5 objects part of a canvas and only one of them will be changing per frame. Although the other 4 text objects are static, any change to any of the objects on that canvas will result in all 5 objects being re-processed.

    Unfortunately, this additional processing is part of how the Unity 4.6 and the new CanvasRenderer system works. I believe you can get around some of those issues by grouping the static objects together in one Canvas and grouping the dynamic one into a separate Canvas where only the changing items would get reprocessed. This would help performance but could result in a messy hierarchy.

    In terms of TextMesh Pro, if you choose to purchase it at some point, be sure to register to the TextMesh Pro User Forum and then make a post providing additional information on your setup, I can take a look and see if I have any ideas on how to improve overall performance and make sure that no additional processing is happening. It is pretty easy via scripting to cause additional processing when nothing is needed.
     
    Last edited: Dec 2, 2014
  38. lightningGamer

    lightningGamer

    Joined:
    Feb 19, 2013
    Posts:
    52
    Okay Thank you very much for the info!
     
  39. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Animating Vertices per Character
    Using TextMeshPro.textInfo.characterInfo[] to access information about each of the characters in a block of text, I applied a simple matrix rotation to rotate / reveal each character.


    The gif animation didn't come out too good but you get the idea.

    Here is an image of the text object selected in the editor.
     
    LampRabbit likes this.
  40. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    What constitutes a changing dynamic object vs a static one? This is what I'm assuming, can you please confirm?

    1. Object position/scale/rotation doesn't change within canvas, text value doesn't change = static
    2. Object position/scale/rotation changes within canvas = dynamic
    3. Object position/scale/rotation doesn't change within canvas, text value changes = static for uGUI, dynamic for TextMeshPro?

    Thank you
     
  41. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The way the new Canvas is designed, any change that affects the vertex attributes of any object contained within this same canvas will result in all of them getting processed whether or not their own vertex attributes were changed. This behavior is identical for all elements contained in a Canvas including TextMesh Pro.

    Here is a quote from Tim Cooper
    In my opinion, in the quest to achieve the smallest amount of draw calls which was so important back in the iPhone 3 days, a lot of extra processing is done which unfortunately in my opinion is worst than what the performance impact of having those extra draw calls would have been.

    P.S. The TextMesh Pro component that works with the Mesh Renderer is not impacted by those limitations. So for objects in a scene like floating text, thought bubbles, etc I would use the normal TextMesh Pro Component. For ui (overlay) text, I would use the TextMesh Pro UGUI component. I would follow Tim's advice and group all static UI elements together and put the dynamic ones into their own individual canvas if possible.
     
    Last edited: Dec 5, 2014
  42. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Thank you. Still trying to figure out exactly what is evaluated as static and what is dynamic. So is this more accurate?

    1. Object position/scale/rotation doesn't change within canvas, text value doesn't change = static
    2. Object position/scale/rotation changes within canvas = dynamic
    3. Object position/scale/rotation doesn't change within canvas, text value changes = static for uGUI (as long as not set to overflow) and TextMeshPro (always)
     
  43. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    This will be as it related to Unity 4.6 using the Canvas
    Correct as long as no other object contained in the same canvas don't change either.
    Correct or if the text changes.
    Not correct. Any change to the text will result in vertices changing and require the mesh to be reprocessed. This will also result in Unity trying to recombine all the elements contained in this canvas.

    There are two things (stages) to think about. (Stage 1) Any change that affects the vertex attributes / layout of the text (ie. the mesh) will require the mesh to be regenerated for TextMesh Pro or for UI Text. Changes made to one TextMesh Pro object doesn't affect the other object. So if 10 are in a Canvas and the text of one is changed, only the changing one is regenerated.

    (Stage 2) Since Unity tried to combine all the elements of a canvas into a single draw call. Any changes made to any of the objects' vertex attributes will result in Unity trying to recombine all those elements. So if 10 objects are in a Canvas and only one changes, then Unity will still try to recombine all 10.
     
  44. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Thank you. It's becoming clearer now. So it would be best to place all text label objects on one canvas (Health, ammo, lives) and the text value objects on another canvas ("87", "233", "3"), correct? That way it will only be 3 text objects being redrawn each time one of those values changes.

    But now I'm thinking, why not have one canvas per text value object? That way only that one single object that is changing gets redrawn. Sure it will be a potentially messy hierarchy - I can live with that for performance.

    But does each canvas take up a draw call? Are a few extra draw calls worth not recombining a bunch of text objects every frame? What is your expert opinion. Thank you once again.
     
  45. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    That is what I would be inclined to do based on Tim Cooper's recommendations.

    Since I have been busy with getting the support for Unity 4.6 added, I haven't had a chance to do much testing on the new Canvas system. It does look like having extra canvases will result in more draw calls.

    3 text objects sharing the same material in one Canvas is 1 draw call as they batch. The same 3 objects sharing the same material in 3 different canvas is 3 draw calls.

    So what needs to be tested is where the performance point tilts in favor of one or the other. Ie. Does having 2 extra draw calls yield better performance vs. Unity having to recombine 3 objects because one changed?
     
    eridani likes this.
  46. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Text Overflow - Page Mode
    I just added a new feature in TextMesh Pro which allows you to control / break blocks of text into pages. Basically instead of Truncating the text that doesn't fit inside a Text Container or RectTransform, it is broken into pages. A new property public int pageToDisplay; which is also exposed in the editor allows you to control which page is shown.

    Instead of using string manipulation to control which portion of the text is shown or creating additional text objects with subsets of the text, this new feature is very efficient as it controls which portion of the mesh is visible by simply degenerating vertices that should not be visible. Since the text is never changed, rich text tags, alignment, word wrapping and all other text layout is preserved.

    Here is a short video showing this new feature.
     
    frikic and LampRabbit like this.
  47. Reiner

    Reiner

    Joined:
    Dec 2, 2012
    Posts:
    214
    Hello here a Sample Image, i mean without the bones. Or as in the second picture

    Greetz Raven





     
  48. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Do you have a link to that TTF font?
     
  49. Reiner

    Reiner

    Joined:
    Dec 2, 2012
    Posts:
    214
  50. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
Thread Status:
Not open for further replies.