Search Unity

TextMesh Pro - Advanced Text Rendering for Unity - Beta now available in Asset Store

Discussion in 'Works In Progress - Archive' started by Stephan-B, Feb 11, 2014.

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

    Redrag

    Joined:
    Apr 27, 2014
    Posts:
    181
    Sorry - didn't realise I was in the wrong forum! I found the answer on the main forum - used the new UI event handling. I still think you could do everyone a favour and include a proper event handling script - maybe put it straight on the prefab.
     
  2. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I am adding an additional example which will use UnityEvent handlers.

    To receive events from a text object, users will need to add a TextEventHandler component to the text object. Then via script or in the editor add a listener for the specific event as per the example below.

    Code (csharp):
    1.  
    2. void OnEnable()
    3. {
    4.      m_TextEventHandler.onCharacterSelection.AddListener(OnCharacterSelection);
    5. }
    6.  
    7. void OnDisable()
    8. {
    9.      m_TextEventHandler.onCharacterSelection.RemoveListener(OnCharacterSelection);
    10. }
    11.  
    12. void OnCharacterSelection(char c, int index)
    13. {
    14.      Debug.Log("Character [" + c + "] at Index: " + index + " has been selected.");
    15. }
    16.  
    Here is the Inspector portion of this new component.

    upload_2016-11-29_3-33-43.png
     
    Last edited: Nov 29, 2016
  3. yarune

    yarune

    Joined:
    Jun 23, 2015
    Posts:
    6
    Hi there,

    Is there a way to display inline sprites behind the text? Now they always display in front when overlapping the text.

    Thanks!
     
  4. alexandre-fiset

    alexandre-fiset

    Joined:
    Mar 19, 2012
    Posts:
    715
    That actually worked! Thank you very much! (Font is BlockGothicRR)
     
  5. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Depending on which TMP component you are using, you can set the Sorting Layer ID and Sorting Order on the normal TMP component.

    On the TMP component for the UI / Canvas, this order is determined by the scene hierarchy which makes it much trickier to manage as the parent text object is always under the sub text objects (childs). One way to handle this is to have all the text be sub objects including the sprites. Basically, you have to use the <font="font asset you want"> to force it to be a child and then make sure the sprite is before that text so it becomes the first child (drawn under the rest).

    This is not an ideal way of dealing with this by any means. I have asked Unity to provide for a method to override the sorting order with the Canvas as using the scene hierarchy isn't always what we want.
     
  6. yarune

    yarune

    Joined:
    Jun 23, 2015
    Posts:
    6
    Thanks a bunch! This is the way to go for me at this point. Unfortunately. Because I had the sprites behind the text (which is variable in length so offsetting isn't an option). :eek::)

    And it requires to have a duplicate of the font another material, because using <font..> for the same font as the default is ignored, and I do want to use the default. Totally understandable from performance point of view.

    EDIT: should be using another material, so <font="Font asset" material="Another material"> ..
    EDIT 2:

    So the solution I use now is <sprite index=1><material="another material">text</material>
     
    Last edited: Nov 30, 2016
  7. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    That would certainly work. Kind of funny that I forgot about the <material> tag o_O
     
  8. Simon75012

    Simon75012

    Joined:
    Sep 15, 2016
    Posts:
    79
    Edit :
    Problem solved with those steps :
    -Delete TextMeshPro folder from Asset folder. (I was able to reopen my project after that)
    -Reimport the plugin
    -I have to select all the fonts again in over 100 area but that's okay. Better than before
     
    Last edited: Dec 1, 2016
  9. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I have been aware of this issue which is the result of a Unity bug introduced late in the Unity 5.3 cycle. The following thread on the TextMesh Pro user forum documents this issue as well as steps to avoid it.

    I posted a comment in the bug report you referenced to provide this information.

    I have submitted a bug report to Unity when I first uncovered this issue which they have confirmed but thus far, they have not been able to resolve it. I will follow up with them again (in light of this other report) to inquire about a time frame for when they expect this to be fixed.
     
  10. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Release 1.0.55 Beta 3
    New release of TextMesh Pro is now available for download on the TextMesh Pro User Forum. As usual, please note that you need to be a registered user / member of the forum to access these releases of the product.

    Please see the following page for the release notes.
     
  11. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Improved the <style> tag handling where Style Opening and Closing Definitions can now contain text as well as tags now affecting each other as if they were inline.



    As seen above, the opening tag will first increase the size of whatever follows by 125%. It will then draw a sprite at this larger size followed by a space + '-' + space at normal size.

    The closing tag does something similar where a space + '-' + space is added before the other sprite.

    Here is the raw text used in this example.



    Producing the following results

     
  12. GemaYue

    GemaYue

    Joined:
    Jul 25, 2014
    Posts:
    2
    Hello, I purchased Textmesh Pro, and found it very powerful and useful, Thanks for creating this wonderful plugin!

    The only problem I found so far is the text disappearing with a position that is larger than about 10000.0 units (In 1 Pixel Per Unit setting in Unity)


    X is at about 10000.0 in this case, in game view there are text not rendering.

    Is there anyway to fix this? Thanks a lot!
     
  13. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Yes. This behavior is by design in order to support Unity's 2D RectMask where a region _ClipRect is defined to determine where the text will get clipped. By default, the range is defined as (-10000, -10000, 10000, 10000) which is why the text disappears at the values you reported.

    This range (_ClipRect) is defined in the debug section of the Material Inspector where you can change it. I recommend changing the value to (-32767, -32767, 32767, 32767) which is the max value for 16 bit which is the limit on some mobile devices.

    In the next release of TMP which is available already on the TMP user forum, the _ClipRect value will now be set to this 16 bit range by default.

    See the following post on the TMP User Forum for more information.
     
  14. ToshoDaimos

    ToshoDaimos

    Joined:
    Jan 30, 2013
    Posts:
    679
    I checked "scripting reference" for Text Mesh Pro and I noticed that its API is very narrow. I work purely in code and don't want to use editor or inspectors at all. Is all that high-level functionality available only in editor? That's hugely limiting for code-driven projects.
     
  15. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Pretty much every aspect of the product / functionality is accessible via scripting / API.

    A lot of functionality has been added over time. With perhaps a few exceptions, all public functions contain summaries but unfortunately, the API docs have not kept up with all these new features / functionality.

    There is a lot of information available on the TMP user forum about many aspects of the API. When in doubt or even when you feel something should be exposed, just feel free to ask / make a request on the TMP user forum.
     
  16. Barliesque

    Barliesque

    Joined:
    Jan 12, 2014
    Posts:
    128
    I've been doing some experimenting with Viktor Chlumsky's MSDF rendering technique, and am now thoroughly convinced that this is the way to go. The comparison Chlumsky makes is between an MSDF image (just the letter A) at 16x16, and a 32x32 SDF image -- where the MSDF image is the clear winner.

    Using that 16x16 graphic (on his GitHub page) as a test, I found it renders perfectly at *all* sizes. Of course, that was with the texture set to Truecolor format; but, switching to 16-Bit compression, I was surprised to find very little loss of quality -- barely discernible rendering that image at 512x512.

    I'd suggest that your comparison appears to show little difference because you're using quite a large point size. See what happens when you take the point size down to 16.
     
    Noisecrime likes this.
  17. KazYamof

    KazYamof

    Joined:
    Jun 26, 2015
    Posts:
    59
    Is possible to replace the default text on InputField to TextMesh Pro?
     
  18. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    TextMesh Pro includes its own Input Field which provides the same basic functionality available in Unity's Input Field as well as some additional features.

    Please note there is a new release of TextMesh Pro available on the TMP user forum. This new release is only available to registered members / users of the product.
     
  19. KazYamof

    KazYamof

    Joined:
    Jun 26, 2015
    Posts:
    59
    Glad hear that! What about the combobox? Has one too? I'm still waiting my aprove on the forum. My company has the asset for almost 6 months, but just now we will invest on upgrade our UI, but we can not broke compatibility between UI 4.6 components and TextMesh pro.
     
  20. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    There is a replacement drop down component as well.
     
  21. czadam_gt

    czadam_gt

    Joined:
    Jan 14, 2016
    Posts:
    7
    aberror.PNG We are experiencing a strange issue. We have a prefab (containing a TextMeshProUGUI component) and we load that prefab from assetbundle. And sometimes (randmoly) on iOS, the TMP text renders incorrectly. If we regenerate the assetbundles, it usually solves the problem (sometimes we have to regenerate it mutiple times to get it working again). And ususally after a few more assetbundle regenerations it randomly gets corrupted again. Any thought on this issue?
     
  22. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I have never seen this issue but it might be related to a new Unity bug introduced late in the 5.3 cycle. Take a look at the following post on the TMP user forum. This could also be due to some texture compression settings but let's start by checking if it is this Unity issue.

    The latest release of TMP which is available on the TMP user forum should further reduce the likelihood of this issue occurring so I suggest you upgrade to the latest release (if the timing is appropriate / ie. you are not about to release your game / project).

    If you are still running into the issue after following the suggestion in the post I provided above, then please provide me with a repro project (privately) as this could be something else.

    P.S. Sorry about the delay in replying. I just got back home from a 40 hour road trip to pickup my daughter who is coming home for the Holidays.
     
  23. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    Could you tell me where I can find that component? I haven't found anything related to drop downs in the current version.
     
  24. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The drop down is located in Create - UI - TextMeshPro - DropDown

     
    silentneedle likes this.
  25. silentneedle

    silentneedle

    Joined:
    Mar 14, 2013
    Posts:
    280
    Hmm it doesn't seem to be there, I'll try to reimport the asset. Or is it because I'm using Unity 5.3?

    edit: reimporting worked, thanks.
     
    Last edited: Jan 14, 2017
    Stephan-B likes this.
  26. jhnissin

    jhnissin

    Joined:
    Sep 7, 2015
    Posts:
    27
    @Stephan-B

    Hey, is there any way to apply an offset to the strikethrough for a font asset? The underlining seems to support this. It seems the strikethrough position is determined by the baseline and the ascender of the font asset, but unfortunately our font asset seems to have the ascender in a weird position. We would like to apply the strikethrough without repositioning all our views in our application and we are wondering if there is a way for us to hack an offset somewhere in the source code for example? :)

    We are using TextMeshPro version 1.0.54.52.
     
  27. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Unfortunately, it is not possible to adjust the StrikeThrough offset at this time. Having said that, this is something that I believe should be pretty simple to add. I'll take a look at this over the next few days.

    In the mean time, the position of the Ascender can be adjusted in the Font Asset Editor. Sometimes, the position of the Ascender and Descender on some font can be really strange. To help visualize these positions, I add a TMP_TextInfoDebugTool.cs to the object.

    Edit / Update - I went ahead and added the ability to specify an offset for the Strikethrough in the font asset editor inspector panel. This will be included in the next release.

    When a new font asset is created, the strikethrough offset will be (ascender + descender) / 2.75. Users will be able to change this value in the font asset editor. Existing font asset will have a default value of zero for the offset which will need to be manually edited.
     
    Last edited: Jan 17, 2017
  28. jhnissin

    jhnissin

    Joined:
    Sep 7, 2015
    Posts:
    27
    Any chance of getting that release early? ;) I think we can't add this ourselves since it would require changing the TMPro_Plugin.dll, which is easier said than done.
     
  29. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The changes are done in the FaceInfo class to add the new property for strikethrough offset as well as in the editor for the font asset editor. Then the changes are done in both the TMPro_Private.cs and TMPro_UGUI_Private.cs file in the region for Strikethrough where this used to be calculated.

    I will try to get a new release out within the next 7 to 10 days which will include this change.
     
  30. jhnissin

    jhnissin

    Joined:
    Sep 7, 2015
    Posts:
    27
    @Stephan-B

    Thanks a lot for the pointers. I wrote a quick implementation for now myself. I'll be looking forward to your next release though. Thanks again for the quick response! :)
     
  31. NoseKills

    NoseKills

    Joined:
    Jun 4, 2013
    Posts:
    25
    Hello and thanks for the great product.

    Hope you'll soon change the various spots with

    Code (csharp):
    1.  
    2. #if !UNITY_5_4
    3.                     case RuntimePlatform.BlackBerryPlayer:
    4. #endif
    5.  
    to for example

    Code (csharp):
    1.  
    2. #if !UNITY_5_4_OR_NEWER
    3.                     case RuntimePlatform.BlackBerryPlayer:
    4. #endif
    5.  
    To make the warnings go away for good :) (5.5.0 onwards)
    Code (csharp):
    1. Assets/TextMesh Pro/Scripts/TMP_InputField.cs(284,42): warning CS0618: `UnityEngine.RuntimePlatform.BlackBerryPlayer' is obsolete: `BlackBerryPlayer export is no longer supported in Unity 5.4+.'
     
  32. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The latest release available on the TMP user forum which is 1.0.55.52 beta 3 already includes these changes along additional fixes and features.
     
  33. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    Hi there,

    I'm using the pagesToDisplay property to set the current page number of a long text I need to show (I'm building an interface for a letter)

    yet, I can't seem to find a public method to get the current total pages!

    It seems weird that it's not included.
    Maybe I missed it? Browsing through the code I believe I found it, but it's not public.

    Could you please help in in getting the total number of pages available to be flipped? (on a TextMeshProUGUI component)

    Thank you.

    Kind Regards,
    Alessandro Salvati

    EDIT: nevermind, I believe it's textInfo.pageCount, isn't it? What about having it on the root of the object as well?
     
    Last edited: Jan 27, 2017
  34. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Correct. The textInfo class and sub structures contains information about the text object which includes metrics / data on each character, word, line, link, etc. This is also how you can access the geometry of the text object.

    I suggest you always check / search on the TMP user forum as most of this type of information has been asked before. Here is a link to one such post http://digitalnativestudios.com/forum/index.php?topic=791.msg5998#msg5998

    There is also an FAQ, Tutorials and lots of additional information on the user forum including online docs as well as early access to new release of TMP and all previous releases.
     
    Last edited: Jan 27, 2017
  35. Wild-Factor

    Wild-Factor

    Joined:
    Oct 11, 2010
    Posts:
    607
    Hi, great plugin !
    I have a question. Is there a way to insert a sprite without having to put it in a sprite asset.
    I wish to use ingame sprite inside a help text without duplicating everything inside an atlas.
     
  36. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The TMP Sprite Asset only contains information about each sprite and a reference the texture which contains them. There is no duplication of the texture or sprites themselves.

    So you still need to create a TMP Sprite Asset which contains the relevant data like offset, scale and advance to be able to insert them within the text as well as name, id and unicode value which would not be available otherwise.
     
  37. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Here is a potential improvement to "Justified" text alignment.

    On the left is the current implementation. On the right is the alternative which still provides control over blending of word and character spacing.

     
    Peter77, NeatWolf and TurboNuke like this.
  38. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    The one on the right has definitely less wide holes and I prefer it.

    But... exactly what has been changed? is the image on the right also using smaller fonts or spacings or is it just an optical illusion?

    I suppose there could be a value that, if changed, could morph the left implementation to the one on the right.

    Something like "preferred words/word breaks count per line". I'm not sure if it's doable tho.
     
  39. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The main difference is that in the current release of TMP Justified text can only expand / grow to fit each line. In this new implementation, the text can both expand and shrink to fit a given line.

    I experimented today with adding controls to limit how much word spacing can expand or shrink as well as character spacing but the difference between this more complex handling and the one used in the right image is marginal. As a result, I am leaning towards keeping the method used on the right side which still provides control over blending between word and character spacing while now being able to expand and shrink which most certainly looks nicer.
     
  40. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    Could a feature like "fit the text in N lines" be implemented using the same principle?

    In the past and even in the present I had to fill exactly, or a maximum of, N lines for layout and font height purposes/
     
  41. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    This could be implemented at the user level via scripting where you would use ForceMeshUpdate() to generate the text layout and populate the textInfo which would allow you to know how many lines the text takes. Then by adjusting the word and character spacing on the text object, iterate until you get the desired number of lines.

    Although the method described above would work, I am not sure about the visual results. You could easily end up with squished text depending on the number of lines you are trying to cut down.
     
    NeatWolf likes this.
  42. NeatWolf

    NeatWolf

    Joined:
    Sep 27, 2013
    Posts:
    924
    What could be the most efficient way/code to do this during a single frame?
    Could you please provide a sample?
    I'm developing on mobile and even if I don't have to set a text each frame, I'd like to avoid hiccups or stuttering.
     
  43. Igorexa

    Igorexa

    Joined:
    Sep 25, 2014
    Posts:
    23
    After install Unity 5.6 get this error:

    Enabling or adding a Renderer during rendering; this is not allowed. Renderer 'TMP SubMesh [TMPro/Sprite]' will not be added.

    How i can fix this?
     
  44. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    As I have stated in several posts / threads, there are still outstanding issue in Unity 5.6. Once these issues have been addressed, I will release a new version of TextMesh Pro for Unity 5.6.
     
  45. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Release 1.0.55.0b8 of TextMesh Pro which includes a version for Unity 5.6 as been uploaded to the Asset Store and should become available shortly.

    Please be sure to review the Release and Upgrade Notes before updating to a new release. As usual be sure to backup your project first.
     
    fffMalzbier and dadude123 like this.
  46. Cachimery

    Cachimery

    Joined:
    Apr 17, 2015
    Posts:
    3
    Hi, I'm trying to make a game menu with angular text, so I'm using the script provided by textmeshpro called "warp text example". When I press play the script works fine curving the text but when I switch to other panel and back to the main panel, the text has change to a horizontal position... Can anyone help to resolve this issue? I have no experience in programming and I believe that this is very simple to resolve but I don't know how to resolve it.

    thanks in advance.

    PD, forgive my english, I'm still learning xD.
     
  47. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    What do you mean by Angular? I am just trying to get a clear understanding of the FX you are trying to apply to the text.

    In terms of the Warp text script, keep in mind that this is a post FX which means it is applied after the text has been generated. This means that any time, you change the text, you need to make sure the FX is applied again. Try taking a look at the script example (warp text) as it should help you understand what is happening there. Take a look at this thread on the TextMesh Pro user forum as it contains a lot of information. Be mindful some of those example are old as they go back to the first release of TMP from years ago.
     
  48. Cachimery

    Cachimery

    Joined:
    Apr 17, 2015
    Posts:
    3
    0

    I mean text along a curve, the text won't regenerate again after change de panel. When I change to the audio panel or the help panel and back to the main panel the text has change to the original position and it never come back to form a curve.

    Thanks for the help.
     
  49. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    If you modify the curve, you might need to force a regeneration of the text and re-apply the curve modifications. Again take a look at the curve script as well as other examples like Vertex Attribute Animation and scripts which should help you understand how this is implemented.
     
  50. Cachimery

    Cachimery

    Joined:
    Apr 17, 2015
    Posts:
    3
    Ok Thanks :)
     
Thread Status:
Not open for further replies.