Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    It doesn't bother me too much, and yeah, trying to keep it short and simple makes sense. It's just that if you have a lot of sprites, like emoticons, you'll need to constantly look up the index.

    Speaking of emoticons, I used NGUI in my last project, which also had inline sprites, but instead of sprite tags, you would define specific character sequences, which would be replaced by corresponding sprites. One advantage of this system, that instantly comes to mind, is chats and input fields. If you want to add an emoticon to your chat message, you just type in the corresponding sequence and it gets substituted with an image. What do you think of this system?
     
  2. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    That is certainly something to consider. I'll have to think about the best way to implement that and where to add the filtering of the text input. I could see having the users define the character sequence in some list which would then be used to do character substitutions.
     
  3. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    It's not very clear to me from watching the video, are these ID's generated automatically? To me it seems they are generated automatically. What happens when I add or remove a sprite from the atlas? Will removing a sprite from the atlas turn every sprite tag in my texts invalid?

    Another thing is that numbers are harder to understand by just looking at the text. Text is most often written outside of Unity in some localization software where no TextMesh Pro live preview is available. While you still need a document that shows the image<>tag mappings for creating new texts, it's easier to understand tags of existing text.

    For example:
    Code (CSharp):
    1. This item costs you {0}<sprite=9>. Press <sprite=10> to continue.
    vs.
    Code (CSharp):
    1. This item costs you {0}<sprite=Gold>. Press <sprite=Silver> to continue.
    Oh see, there is an error! "Silver" should be "ButtonA" instead. Nobody could spot this error by just looking at the text when using numbers instead.

    I would prefer a sprite/font tag system where I can specify a text rather than a number.
     
  4. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Just like for fonts, you will create a Sprite Asset from a texture which was sliced using the Unity Sprite Editor. This Sprite Asset will reference this texture as well as a list of those sprites as provided by Unity Sprite Editor.



    The Index of the sprite is the ID which corresponds the index of the sprites that Unity returns. As you can see in the image below, the Gingerbread Cookie is named Unity "xmas_sticker_full_3" which is the name of the image / texture and _3 for the index of the sprite in the array. In the Sprite Asset, the ID of this sprite matches what Unity provides.



    Using names when there isn't many sprites in the atlas may work fine but when there are 850 sprites in a texture that is likely going to be a challenge. The other issue with names is that it is easy to misspell those names in the sprite tag whereas with ID you could get the ID wrong but it is still something valid.

    I am not opposed to figuring out some method to make names work. You can name the sprites in the Unity Sprite Editor and when editing the texture to add new sprites, the information seems to be preserved including the order / index. My focus was providing the ability to mix graphics with the text, as we move forward, I am open to seeing what can be done to increase the manageability of those sprite assets.
     
  5. Devil_Inside

    Devil_Inside

    Joined:
    Nov 19, 2012
    Posts:
    1,117
    I personally would choose the "emoticon" system over the sprite-tag system. This way, when you create the Sprite Asset, instead of specifying a name, you would specify one, or several character sequences.
    By default every sprite would use it's ID with some "escape characters", for example: !1!, !2!, :15:, :100:, etc.
    If the user wished, he could change the default sequence for a sprite to anything he likes: :candybar:, *gingerbread_man*, =xmas_present=, etc.
     
  6. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Thanks for your answer. As I understand, it seems it requires pre-baked atlases? We use a workflow where artists provide images as separate textures and we use the "Sprite Packing Tag" in Unity's Texture Inspector to tell Unity into which atlas an image goes. We don't use pre-baked atlases in the editor, we use them in builds only (Edit > Preferences > Editor > SpritePackerMode=EnabledForBuilds).

    My concern is that it's not guaranteed that a sprite always gets the same array index as we add and remove images from the atlas (as we add/remove the Sprite Packing Tag). My idea was that this issue could be solved by using either a custom name or maybe even the sprite name rather than the sprite atlas index, because the name stays the same unless you change it.

    However, if this feature limited to providing a pre-baked atlas, I see that it's probably not going to be much of a problem with changing indices. Unfortunately, it's not the workflow we're used to. We really like not using an atlas during development, and would like to keep this workflow.

    We really like TextMesh Pro and the new mixed font/graphics feature is also very useful and appreciated, that's why I would really like to see it working with our workflow too.

    Any thoughts about this?
     
  7. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I think there is a need for both implementation.

    For instance when typing ":" + ")" I would most likely want the smiley face to show up. So in this case those two characters should be associated with some sprite.

    I also think that having the ability to specify <sprite=id" or <sprite="name"> is also needed. Note the name part isn't implemented yet as I need to think of an efficient way to parse the input to look up the matching "name".
     
  8. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Does the artist provide individual images (png) for each sprite or do they provide different images (png) which contains multiple sprites?

    I need to explore what information is available from the Sprite Packer. It doesn't seem like you can get a list (array) of the sprites packed in that atlas. The sprites also cannot be tightly packed since the Text / Sprites for layout purposes are rectangles. The texture that contains those sprites isn't an asset that you can reference so when typing <sprite="Some name"> where do you look for that sprite texture / atlas.

    There is also the issue of how do you allow tweaking of the offsets of the individual sprites and scale since the information doesn't exists in the Sprite class.

    After the first release, I'll look further into whether or not the Sprite Packer could be used and if the API for it has all the functionality that would be needed.

    Right now for the first release, you will have to create a Sprite Asset just like you create Font Assets which contain all the relevant information for the Sprites to be adjusted and displayed.
     
  9. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Our artists provide individual images for each sprite. Basically one icon/graphic per (sprite)texture. These individual images are set to TextureType=Sprite in Unity's Texture Importer and by using the Sprite Packing Tag, we can tell Unity that we would like to have these individual images be packed in an atlas. Depending on the number and size of each sprite, Unity might create multiple atlases.

    Maybe you don't really have to, see my idea below.

    I thought so. While it would be neat to have support for that, it's not very important for me personally.

    References to individual sprites in the project stay intact after Unity created the atlas. It seems Unity magically patches/replaces such references during play or build.

    Here is how I picture support for both workflows could be implemented:

    A TextMesh Pro Sprite List entry would have a Sprite reference, where users can drag&drop a Sprite from the project. Implementing support to automatically add all sprites of an atlas (one texture that contains multiple sprites) to the list should be trivial, so it's little effort for the user to add 1000 sprites to that list and is pretty close to with what you came up already.

    The ID needs to be stable. Maybe implement functionality to make that number only increase per added list entry, but never let it decrease. Once a list entry has been added, it's guaranteed that this ID stays the same no matter what. Plus the list entry also needs all your extra data OX, OY, Adv, etc. I would probably get rid of the "Sprite Atlas" field in your TextMesh Pro Sprite Asset too, because it's not necessary anymore and does not work with the workflow we use. Since you have references to each individual sprite, you have a reference to the atlas(es) automatically too (sprite.texture).

    When the TextMesh Pro Sprite Asset is loaded/created, you setup your lookup tables, I guess you just need to calculate UV's. The Sprite references are all patched by Unity and point to the atlas at this time, in case of 1) atlasing is enabled or 2) the sprite comes from a image that contains multiple sprites.

    You use the rect, texture and textureRect properties of each Sprite to figure out the UV's. (The texture property either points to the texture or atlas). Since the Sprite List Entry contains the ID <> Sprite binding, you should have everything you need at this point.

    Your Sprite drawing code needs to handle if sprites in one text are not on the same atlas. If you have this code, it should automatically work with individual textures too.

    Hope it makes sense.

    I'm not sure what you referring to. What offsets and scale do you mean?
     
  10. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    508
    Hi,

    Thanks for this amazing asset.

    But I have one draw call by "TextMesh". What can I do for this ?

    Thanks !

    Regards,

    AB
     
  11. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    You are welcome :)

    What do you mean exactly?
     
  12. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    508
    Thanks for your quick answer.

    If I have a GameObject with a TextMesh "1", and another one with another TextMesh "2", I have two draw calls.
     
  13. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Are they both using the same Font Asset and Material for both objects?
     
  14. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Here is another preview of the <sprite=id> tag.

    Sceneview with object selected


    Gameview (Play mode)


    This is using the same TeleType script using the TextMeshPro.maxVisibleCharacters property.

    P.S. See if you notice the little extra at the end of the sequence :)
     
    Last edited: Feb 3, 2015
  15. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I'll make a new video tomorrow going over those two items.

    I have also been thinking / exploring a few options and I think the Sprite Packer could be supported.
     
  16. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    508
    Yes, I'm using one of your font asset and material you provided with your asset.
     
  17. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    As long as they are all using the same Font Asset / Material, they should be dynamically batching. Note that dynamic batching is a Unity Pro feature.

    Here is an screenshot with 5 text objects. As you can see from the stats, 1 draw call for the background and 1 + 4 saved by batching for a total of 2 draw calls.



    If you are using Unity 4.6, you can get the latest beta release of TextMesh Pro which includes support for Unity 4.6 and the new UI. When using the TextMeshPro UGUI Component which uses the Canvas system, Unity handles the batching of the UI elements for this new system.

    If you haven't done so already, please take the time to register to the TextMesh Pro User Forum. Once approved, you'll get access to the latest beta releases of TextMesh Pro which include new features and support for Unity 4.6.
     
  18. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    508
    Hi,


    Thanks.


    My textMesh are moving, but I don't touch the scale (1,1,1). Do you think it's the problem ?

    Thanks !
     
  19. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    They should still batch. In the examples folder load scene Benchmark (Floating Text). I my end, I get 7 draw calls and 499 saved by batching. You should be getting the same results.

    Also in player settings, it is possible that Dynamic Batching is unchecked for you.

    I'll check back tomorrow morning since it is already 5:00 AM for me and time to sleep :)
     
  20. BonyYousuf

    BonyYousuf

    Joined:
    Aug 22, 2013
    Posts:
    110
    Hey,
    I have spent few times regarding how font works to understand where my problem really lies on showing bangla fonts. Here is the thing, like hindi(indian language) our bangla also has a lot of conjucted letters(letter created with multiple letters). read this section http://en.wikipedia.org/wiki/Bengali_alphabet#Consonant_conjuncts
    These letters are created with typing few unicode characters without any space. For example the last letter ক্ষ of the word রক্ষা is written with these three letters without any space ক ্ ষ

    On any unicode supported text editor if you type/paste these letters without space, they automatically change to the letter ক্ষ. But on unity it does not, the letters are shown separately.

    Do you know any fix for this? It happens with your own asset or with unity's default text field.
     
  21. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    When a user types text in an EditorGUI.TextArea for instance, Unity returns the text that was typed. Unfortunately, Unity isn't interpreting or returning the correct characters when those Bangla characters are typed.

    I am curious if other languages that use similar features also have the same issues.

    The easiest solution for this would be to have Unity correctly interpret your language and return the correct Unicodes.
     
  22. tellemstevedave

    tellemstevedave

    Joined:
    Jul 15, 2013
    Posts:
    21
    I just bought TMP yesterday. I'm excited to try it out with the new UI stuff. How long does it take to get registered on your forums? I registered yesterday so I could the latest beta.
     
  23. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    It is usually pretty fast unless I am sleeping or unless the invoice # is wrong. I just doubled checked and it appears the invoice # you used in the registration isn't correct. I just sent you an email about it. As soon as you get me a revised invoice # that I can validate, I'll promptly approve your registration.

    Sorry about the delay
     
  24. BonyYousuf

    BonyYousuf

    Joined:
    Aug 22, 2013
    Posts:
    110
    Hi,
    I am creating a table with the new UI. Currently for each cell i would have to create a new text field and align it(sometimes its left align sometimes center). But to me this is an overkill. I would rather have one large text field for the entire row to save memory. But then I would have to manually calculate and position/align the texts for each cell so I can imitate what I am currently doing with multiple text field
    I was wondering if TextMesh has any clever way to handle this issue. If not, please think of adding it. It would really help out a lot of users.

    Thanks
     
  25. ababab5

    ababab5

    Joined:
    Apr 15, 2014
    Posts:
    508
    Ok I just find where is the issue : I change the color of my textMeshes at start with :

    textMeshPro.color = Constant.Instance.TextMeshColor;
    textMeshPro.faceColor = Constant.Instance.TextMeshColor;
    textMeshPro.outlineColor = Constant.Instance.TextMeshColor;
    textMeshPro.fontMaterial.color = Constant.Instance.TextMeshColor;

    How can I change dynamically my colors and avoid this issue please ? Thanks !
     
  26. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    TextMeshPro.color corresponds to the vertex colors.
    The others are material properties which will be multiplicative to the vertex color. Accessing material properties directly will result in an instance of the material being created. This is the norm in Unity.

    Take a look at the following video which should help you get a better understanding of these.
     
  27. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Support for tables has been requested. It is on the list of things. In the mean time, you could look into using the <pos=xx.x> tag which is like a tab stop that you can position. It doesn't provide the ability to align different word differently on each line but at least it would enable you to create the appearance of tables.

    Here is an example of using the <pos=xx.x> tag. The tags <allcaps> are all aligned using that tag.
     
  28. thienhaflash

    thienhaflash

    Joined:
    Jun 16, 2012
    Posts:
    513
    Do you have any idea on making it works with NGUI / uGUI?
    If TMP can be used to replace the normal label / input in NGUI / uGUI then it's absolutely cool !
     
  29. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    TextMesh Pro is already used by several users as a replacement for the text label in NGUI or a replacement for the UI Text component in Unity 4.6.

    I don't have to run time input component done yet but that is planned.
     
  30. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    Do you estimate when you will have TextMeshPro version of Input Field?
     
  31. thienhaflash

    thienhaflash

    Joined:
    Jun 16, 2012
    Posts:
    513
    Currently the implementation, I guess, would be adding one or several sorting layers (not sure are there any limit on the number of layers ? ) then when we have multiple panels (that contains NGUI sprites & TMP texts - 2 drawcalls, like a two slice bread) over each other, we will need to create multiple sorting layers, right ?
    By support NGUI I mean we can find someway to do that automatically, maybe add a TMPWidget just like a normal UILabel and everything magically just works ? Do you think it's doable ?
     
  32. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    TextMesh Pro uses Unity's sorting layers. There is likely a limit but I have never checked to see how many layers are supported.

    I think implementing some type of NGUI widget that would automate this process would be very nice. I do have several users using TextMeshPro with NGUI so it appears to work for them. I simply haven't had the time to dive into NGUI to look into a closer integration.

    Now as far as Unity 4.6 and the new UI, the latest beta release of TextMesh Pro available on the user forum includes a TextMeshPro UGUI Component which is designed for the Canvas system.


    P.S. Sorry about the delay in response. Not sure what is up with the Alert System on the forum and it not doing it thing from time to time.
     
  33. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Beta Release 0.1.46 Beta 4
    The latest beta release of TextMesh Pro which includes the new <sprite=xx> tag which works with the new UI is now available to all registered users of the product on the TextMesh Pro User Forum.

    Here is a video introduction to the new sprite tag feature.
     
    Crazydadz and Devil_Inside like this.
  34. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    Can we add in sprite=xx simple 2d sprites from our 2d game atlas?
     
  35. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The sprites are contained within a texture which is spliced using Unity Sprite Editor. So you should be able to use your texture (atlas) to slice them and then create the Sprite Asset from the result. That part is covered in the video above unless I misunderstood your question.
     
  36. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    I have the latest version. I have a font asset with 1068 characters. 2048x2048. When I run my game in editor I get multiple error messages. All the same. "NullReferenceException: Object reference not set to an instance of an object
    TMPro.TextMeshProUGUI.OnValidate () (at Assets/TextMesh Pro/Scripts/TMPro_UGUI_Private.cs:597)". After that it works with no issues. What is it? How to fix this?
     
  37. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Have you moved the TextMeshPro folder to a different location or moved the Resources Folder which contains the ARIAL SDF Font Asset?

    If the answer is no to either of those questions, would you be able to create a Repro project and email it to me or send me a private message on the TextMesh Pro User Forum with the Repro Project?

    Edit: Actually is there a warning message that shows up in the console before these error occur?
     
  38. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    Moved: No.
    Warning message: No.
    The errors went away when I loaded another scene run it and then reloaded the previous scene. Now it doesnt show it at all. Does this make any sence?
     
  39. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Yes. It looks like something wasn't serialized in that scene. I would love to figure out why exactly. If you are still able to reproduce those errors with that scene, I would love to take a look at it.
     
  40. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    No, now I changed many scenes but the errors are gone.
     
  41. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I have only seen those when loading an older scene into a newer release but I can never manage to reproduce it. I started keeping packages of older scenes which I try in newer release but those errors fear me and never show up for me :)
     
  42. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    If I see it again I will let you know.
     
  43. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    I have noticed another issue that happens only in Greek Language.



    Here is my settings window with TextMeshPro.
    Eg: I use the word 'Settings' with "FontStyles.SmallCaps" and you see the outcome in the top image.
    When I change to the Greek 'Settings' equivelant which is 'Ρυθμίσεις' it gets messed up with "FontStyles.SmallCaps" because it tried to change the toned letter i = "ί" to capital and it mistakly puts another letter where the correct one should be 'I'. Also another issue with the s at the end which is 'ς' and its capital is 'Σ' and but it doesnt find it. Same thing happens to 'Music' and 'Language' and much more. Without "FontStyles.SmallCaps" it works ok. Maybe the same thing happens to other languages with tones.
     
  44. behnke101

    behnke101

    Joined:
    Apr 19, 2013
    Posts:
    4
    I just downloaded the TextMesh Pro from the asset store and I see no options for using this on the new canvas system. There are no TexMesh Pro options under the UI only to create a TextMesh Pro Text. Any idea of what the deal is?
     
  45. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The latest beta release which includes new features as well as support for Unity 4.6 and the new UI is available to all registered users of the product on the TextMesh Pro User Forum.

    I approved your registration to the user forum earlier today. The latest beta releases are available in the "TMPro - Alpha & Beta Releases" section of the forum.
     
  46. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Can you post what the correct lower case vs upper case of those two words are so I can check to make sure it uses the correct characters?
     
  47. giorgos_gs

    giorgos_gs

    Joined:
    Apr 23, 2014
    Posts:
    623
    Correct lower case vowels with tone to higher case:
    ή = Η
    ί = Ι
    ό = Ο
    ά = Α
    ώ = Ω
    έ = Ε
    ύ = Υ
    ς = Σ
    ϊ = Ι
    ϋ = Υ
    This covers it.
     
  48. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Thank you for providing this additional information. The reason why this is wrong is simply because I was either adding 32 or subtracting 32 to convert from upper to lower case letters which works for plain ASCII but is clearly wrong for other languages.

    Now I need to research the proper way of handling this.
     
    giorgos_gs likes this.
  49. zangad

    zangad

    Joined:
    Nov 17, 2012
    Posts:
    355
    Hi, I'm trying to use Text Mesh Pro for our card game which has a lot of small text, and I'm having trouble getting the font to look good at smaller sizes.

    I thought it might be my font, but I switched to the Arial font included in your package and got the same results, so it's not the font. I thought it might be my monitor's resolution, but the same font at the same size looks much better in Photoshop, so it's not my monitor.

    So I setup a side-by-side comparison, one using Text Mesh Pro and one using uGUI 4.6 Text UI. The font I'm using is one that's highly readable at smaller sizes (Segoe UI). The Text Mesh Pro font looks better inside the Unity Editor, but when I run the game, the uGUI font looks much better. Here's a screenshot:



    Is there something special I need to do in order to get the Text Mesh Pro font looking as good as the uGUI 4.6 font at small sizes? My understanding is the Text Mesh Pro version should look as good, if not better, at all sizes. I've tried using the underlayment setting as mentioned in the user guide for small text, but that just made it more bold and blurry.
     
  50. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    There are few things that should help. First when an outline is added to the font, the outline expands both inward and outward from the edge which means it reduces the surface area of the face of the text. So if the outline is .1 in thickness, adding dilation of .1 will offset what was reduce by the outline.

    Next, at same size, clipping can occur so I would enable the extra padding setting in the editor panel.

    Lastly, the color space does affect the rendering of the text and using Linear Space in the player settings tends to yield better results.

    Those options should help. Let me know how it turns out.
     
Thread Status:
Not open for further replies.