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. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Just a quick note: When creating a new Font Asset using some TTF file, you have to make sure you use the Font Render Mode (Distance Field 16 or 32). Using any other Render Modes will create a Bitmap Font Asset and assign the TMPro/Bitmap Shader to it.

    When a Font Asset is created using the Distance Field 16 or 32, the TMPro/Distance Field shader is assigned to it.

    There should be no difference between using an SDF or Bitmap Font Asset in terms of changing the alpha. BTW: Are you changing the TextMeshPro.color property or are you changing the material?

    I would suggest, you register to the TextMesh Pro User Forum and then in the support section, post your request for help as well as your script so I can take a look at it which would make it easier to help you out.
     
  2. ade76

    ade76

    Joined:
    Apr 9, 2014
    Posts:
    19
    Ok will post in forum later(my children are currently playing havoc :/) but just to be clear here for now:)

    All I'm trying to do is use iTween to fade text mesh pro items in. As i would prefer to use iTween if possible as I have set up quite a lot of stuff with it already....

    Now if I use bitmap material then iTweens alpha fade works.

    If i use Distance field then it doesn't and comes up with an error:

    ---------------
    Material doesn't have a colour property '_Color'
    Material doesn't have a color property '_Color'
    UnityEngine.Material:get_color()
    iTween:ColorFrom(GameObject, Hashtable) (at Assets/iTweenEditor/iTween.cs:703)
    iTween:FadeFrom(GameObject, Hashtable) (at Assets/iTweenEditor/iTween.cs:523)
    <StartEvent>c__Iterator19:MoveNext() (at Assets/iTweenEditor/iTweenEvent.cs:247)
    UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
    ----------------
     
  3. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    You should be changing the TextMeshPro.color property and not the material property. Why?

    Changing the Material property will result in Instances of the material which will result in breaking batching and thus more draw calls. Whereas changing the TextMeshPro.color property changes the vertex color which allows you to still use the same material on all text objects thus making it possible to batch them and saving on draw calls.

    Using TextMesh or TextMeshPro, you should be using iTween to change the .color property not the material color.

    P.S. Just in case someday you wish to change the Material properties directly, the Material Property for the color of the face of the text is "_FaceColor". The Material Property for the Outline color is "_OutlineColor". I haven't played with iTween but I would presume it can also access those properties.

    P.S.S. Accessing Material Properties by string name is slower than using their PropertyID. To access the material properties via the ID's, TextMeshPro has a utility class which caches those.

    Here is an example to change the face color.
    Code (CSharp):
    1.  m_material.SetColor(ShaderUtilities.ID_FaceColor, new Color32(255, 255, 255, 128));
    P.S.S.S. If that makes sense :D I am off to bed since it is 3:30 AM. Feel free to reach out if you need any additional help with this.
     
    Last edited: Oct 5, 2014
  4. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,551
    This is a great tool. It is really amazing how little work it takes to get such good results and to easily test out new ideas. Glad I have it in my toolbox now.
     
  5. ade76

    ade76

    Joined:
    Apr 9, 2014
    Posts:
    19

    Hi again

    I hope you had a good sleep but sadly I'm back again as can't work this out:/

    Your above does kinda of make sense but I simply am not understanding how to target the colour vs material using iTween.



    When I was using a text mesh i was able to simply create a text mesh object and drag a script like this:

    -----------------
    usingUnityEngine;
    usingSystem.Collections;


    publicclassTestTween : MonoBehaviour
    {

    voidStart(){
    iTween.FadeFrom(gameObject ,iTween.Hash("alpha",0,"time",2,"delay",1));
    }
    }
    -----------------

    And this fades it in.

    I'm stuck on how to do the same with a textMeshPro object as when and do the same I get that error I posted before. Namely iTweens default handling of a textMeshPro object seems to not work?

    Material doesn't have a color property '_Color'
    UnityEngine.Material:get_color()
    iTween:ColorFrom(GameObject, Hashtable) (at Assets/Plugins/Pixelplacement/iTween/iTween.cs:707)
    iTween:FadeFrom(GameObject, Hashtable) (at Assets/Plugins/Pixelplacement/iTween/iTween.cs:527)

    *as part of the test i am using the impact sdf font part of text mesh pro install. And the material is set to mobile/Distance Field

    I appreciate your help so far:)

    ade
     
  6. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I have never used iTween so I don't know if there is a way to tell it what custom properties of an object to access. However, I have looked at the iTween code that deals with color and made the following changes to enable it to change / modify the TextMeshPro.color property

    You will have to make the following changes yourself.
    1. Move the iTween folder from the Plugins folder to another folder like StandardAssets. This is needed so we can add the TMPro namespace.
    2. Make the following changes iTween.cs file.

    Code (csharp):
    1.  
    2. // In the Namespaces region, add the following
    3. using TMPro;
    4.  
    5. // In the ColorFrom Function we need to add the code to check and get the color from the TextMeshPro.color property.
    6.  
    7. //set tempColor and base fromColor:
    8. if(target.GetComponent<GUITexture>()){
    9.             tempColor=fromColor=target.guiTexture.color;  
    10. }else if(target.GetComponent<GUIText>()){
    11.             tempColor=fromColor=target.guiText.material.color;
    12. }
    13. // Insert here...
    14. else if(target.GetComponent<TextMeshPro>())
    15. {
    16.             tempColor=fromColor=target.GetComponent<TextMeshPro>().color;      
    17. } // End insert
    18. else if(target.renderer){
    19.             tempColor=fromColor=target.renderer.material.color;
    20. }else if(target.light){
    21.             tempColor=fromColor=target.light.color;
    22. }
    23.  
    24. // Still in the ColorFrom function...
    25.  
    26. //apply fromColor:
    27. if(target.GetComponent<GUITexture>()){
    28.             target.guiTexture.color=fromColor;  
    29. }else if(target.GetComponent<GUIText>()){
    30.             target.guiText.material.color=fromColor;
    31. } // Insert here...
    32. else if (target.GetComponent<TextMeshPro>())
    33. {
    34.             target.GetComponent<TextMeshPro>().color = fromColor;
    35. } // End Insert
    36. else if(target.renderer){
    37.             target.renderer.material.color=fromColor;
    38. }else if(target.light){
    39.             target.light.color=fromColor;
    40. }
    41.  
    42. // Lastly in the GenerateColorToTarget, we also add some new code
    43.  
    44. //from and init to values:
    45. if(GetComponent<GUITexture>()){
    46.             colors = new Color[1,3];
    47.             colors[0,0] = colors[0,1] = guiTexture.color;
    48. }else if(GetComponent<GUIText>()){
    49.             colors = new Color[1,3];
    50.             colors[0,0] = colors[0,1] = guiText.material.color;
    51. } // Insert here...
    52. else if (GetComponent<TextMeshPro>())
    53. {
    54.             colors = new Color[1, 3];
    55.             colors[0, 0] = colors[0, 1] = GetComponent<TextMeshPro>().color;          
    56. } // end insert
    57. else if(renderer){ ...
    58.  
    59.  
    With these changes, I was able to fade the vertex color of the TextMeshPro object using iTween. Like I said, I have never used iTween. There might be a way to have it use custom properties of custom objects. Maybe someone familiar with it can chime in.
     
  7. ade76

    ade76

    Joined:
    Apr 9, 2014
    Posts:
    19
    Thanks of ridging into this Stephen. It doesn't break now but it doesn't seem to actually interpolate between the values. I am going to look at some other tween engines as in my googling yesterday some had issues with 2dtoolkit objects and iTween and it sounded like they same/similar problem.
     
  8. ade76

    ade76

    Joined:
    Apr 9, 2014
    Posts:
    19
    Sorry for typos in last post

    ridging = digging

    Stephen = Stephan

    :/
     
  9. ade76

    ade76

    Joined:
    Apr 9, 2014
    Posts:
    19
    Hi

    Just a brief update in regards tweening systems and text mesh pro, in case this is of use to anyone else:)

    I have shifted over from iTween to LeanTween....this lets you set custom properties (so can modify text mesh colour property to fade in and out etc) so it does what I need which is great news:)

    ITween may well do but I just found Lean Tween easier to run with
     
  10. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Glad to know that LeanTween works with custom properties and for you :)
     
  11. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Took a short break from working on the support for Unity 4.6's Auto Layout System.

    This is another simple script which tweaks the position of the vertices. What is kind of cool about this, is that I can actually change the text or properties of the object like alignment, character spacing, etc and the letters keep on dangling around :) I'll try to make a short video showing that off tomorrow.

     
  12. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Made some tweaks to the example Vertex Attribute Animation script. In this example I am applying and offset to the position of each character as well as random rotation.


    These changes now make it possible to change the text and property of the object at run-time while those FX are still on-going.
     
  13. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Here is a Side by Side of TextMesh Pro vs. UI Text in Unity 4.6.
     
    hopeful likes this.
  14. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Just testing stuff out (well maybe a bit of playing around) :)



    This text style is using vertex gradient colors along with some Outline with a bit of dilation. You can also see the bevel and soft shadow along with the blue glow.

    I am also using a small script to animate the vertex positions using an animation curve.
     
  15. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Here is the text before and then after tweaking the material properties.



     
  16. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Basically most of the properties of the text object can be changed as run-time. Here I am simply changing the curve scale.

     
  17. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    324
    Any idea why my fonts aren't rendering properly at runtime?

    In the editor they look fine, but at runtime, all I get are white squares. This happens with all the default SDF fonts, as well as the ones I create myself. If I use a bitmap font, it renders fine.

    Text on left is using BitmapFont, other are using SDF font:
     
  18. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    324
    Err, they were rendering properly in the editor, but now have somehow become corrupted, rendering very thin outlines around each letter. If I change to one of the pre-supplied SDF fonts it renders ok (Still broken at runtime though)

    Again, image on left is using Bitmap, other 2 are SDF:
     
  19. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Hi Shawn,

    Can you load the example scene 01 that came with TextMesh Pro and see if the renders correctly at a build on your end. Make sure that it is still using the TMPro/Mobile/Distance Field shader.

    Can you also give me some information on what version of Unity you are running and it looks like a PC right.

    Please take the time to register to the TextMesh Pro User Forum which will make it easier to help you out and where you will also find solutions to potentially similar problems. If it is more convenient for you to email me, please feel free to do so at Support@DigitalNativeStudios.com.

    P.S. Now that I saw your post, I'll be standing by my email to get your update so I can help you get this sorted out.
     
  20. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    324
    Good news, I found the problem :D Setting the localScale.z = 0 caused the TMP instances to render as white squares. For bitmapFonts, this seems not to be a problem.

    We had some code that was scaling the transforms of our GUI, to match the zoom of the Camera. The fix was to change this line:
    guiParent.transform.localScale = new Vector2(uiScale, uiScale);
    to:
    guiParent.transform.localScale = new Vector3(uiScale, uiScale, 1);

    Working like a champ now! Thanks for the amazing plugin, very impressive work.
     
  21. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Glad you figured it out. Object scale needs to be uniform in order for the object to render correctly using the Distance Field shaders.

    Thank you for the kind words :)

    Please feel free to reach out to me should you run into any other issues. Also be sure to register to the TextMesh Pro User forum and to visit there as well since you will find lots of additional information and video tutorials there.
     
  22. shawnblais

    shawnblais

    Joined:
    Oct 11, 2012
    Posts:
    324
    Should this be the case even in Orthographic mode? z-scale seems to have no effect as long as it's >1 anyways, and for 2d games we generally don't bother setting z on anything (except the camera). So would be nice to not have this edge case if it's possible.
    Cheers,
     
  23. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Uniform scaling should be used at all times for proper rendering. Some deviation can be ok but in the case of X,Y will deform the text so it isn't really advisable. More importantly, non-uniform scaling breaks dynamic batching in Unity so that is another reason not to deviate from it. Now, if I recall correctly that might (is) change in 5.0 but thus far it has been the case.
     
  24. tayl0r

    tayl0r

    Joined:
    Jan 6, 2012
    Posts:
    85
    Stephan - it doesn't seem like TextMesh Pro support automatic text scaling so a piece of text fits into a specific width? (shrink to fit)

    That is a must have feature. Do you have any plans to add it?

    I've added this feature to both Text Box 1 and TK2DTextMesh and I'm a bit tired of adding it myself.
     
    Last edited: Oct 30, 2014
  25. tayl0r

    tayl0r

    Joined:
    Jan 6, 2012
    Posts:
    85
    How do you make the material presets? Like in your examples you include a bunch of materials for each font, such as "ARIAL SDF Ortho.mat"

    How are you creating those? I don't see where you find the texture to link in. The texture seems to be hidden from the Project view, and I don't see any valid Material to duplicate either.
     
  26. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    That feature is called "Text Auto-Sizing" and is available in the beta 0.1.45 & 0.1.46 which haven't been released yet. However, those two versions are available to registered users who wish to help out in the testing of these releases to make sure they are ready for general release.

    To get access to these early releases, please visit the TextMesh Pro User Forum and register. Once you have done so, PM me here or email me via support@DigitalNativeStudios.com to let me know what username you have selected and I will add you to the private beta group.
     
  27. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I added a Context Menu to the material editor which allows for easy duplication and assignment of materials. You can watch the following video which will explain this feature and options.
     
  28. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Added some additional Rich Text tags
    The new tags provide the ability to do "All caps", "Small Caps", and control character spacing within the body of the text. Here is an example of these new tags.



    Also note the use of <size=%150> to make the first line larger. <sup> for the "Pro!" and <u> for underline. The tag examples are aligned using the <pos=x.xx> tag.
     
  29. Smolli

    Smolli

    Joined:
    Mar 12, 2014
    Posts:
    84
    Hi Stephan,

    this seems very much like all I ever wanted for text in Unity. But before I buy it I would like to know if it supports Playmaker. I googled and searched around (also on your forum) but didn't find any statement. As my current project depends text-wise on playmaker (and much of the other stuff, too) I don't know if TMp would actually be usable for me.

    Playmaker and and a nice Input-System, that's what I would need :)

    Thanks
     
  30. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    TextMesh Pro does work with PlayMaker. Here is a quote from one of my users which was posted on the previous page.

    Once you get TextMesh Pro, please be sure to register to the TextMesh Pro User Forum. Once you have done so, send me a PM and I will get you access to the latest Beta for Unity 0.1.45 or 0.1.46 which includes several new features but more importantly a minor tweak to vertex colors to make it play nicer with PlayMaker.
     
  31. Smolli

    Smolli

    Joined:
    Mar 12, 2014
    Posts:
    84
    Uhhhh, damnit, now you got yourself another buyer and me an angry wife :)
     
  32. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Thank you and sorry ;)
     
  33. Smolli

    Smolli

    Joined:
    Mar 12, 2014
    Posts:
    84
    I'll her that it's your fault ;)

    Last question (for now): is the newest beta safe enough to replace the text I have now. I know, it's some work to change it all, but I'm fed up with the blurry text or having to do the scaling trick to have it sharp it enough. So, the sooner I can change the better it is.
     
  34. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    I have been using those Betas for a while now for making demos / videos as well as my users and the latest beta is pretty solid especially when it comes to the normal TextMeshPro Component for Unity 4.3 ~ 4.5.

    The TextMeshProUGUI Component for Unity 4.6 is also looking good but since Unity 4.6 is still in beta and evolving, I am still working on a few more things there.

    BTW: The latest beta works with Unity 4.3 and above although it is labeled as 0.1.46. Again, be sure to register to the TextMesh Pro and send me a PM with your username and I will add you to the Private Beta Group.
     
  35. Smolli

    Smolli

    Joined:
    Mar 12, 2014
    Posts:
    84
    Cool. I'm using 4.6 because of uGUI, but no fancy text stuff, so it should be good to work with. Great! Thanks for your quick replies.
     
  36. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    You are welcome. Feel free to reach out to me should you need anything.
     
  37. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Animating UV offset
    This is just an experiment based on the suggestion of one of TextMesh Pro's users.



    The speed of the offset would be a material property and thus could be changed manually or via script.
     
  38. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    UV Vertex Offset Animation
    This new feature allows to control the speed of the UV offset to either animated the face and / or outline texture.



    This feature is available on the Normal Distance Field Shader as well as the Surface Distance Field Shader.

    Here is another example animating the outline texture UV offset.

     
  39. Smolli

    Smolli

    Joined:
    Mar 12, 2014
    Posts:
    84
    Seems that with Playmaker you can only change the TMPGui-Text, not the normal TMP-Text. Tried uscript, and that works, but I don't want to use both (or pay for uscript, but the ple-version is great for testing and evaluation).

    You wouldn't want to add a TMP-Addon to PM, wouldn't you? :) That would certainly booooost the sales :))))
     
  40. Smolli

    Smolli

    Joined:
    Mar 12, 2014
    Posts:
    84
    Okidoki, got it, when using 'send Message' from Playmaker I can do all I want. Or I can write a little function that sets the properties I want. All is good, all is great :))
     
  41. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    What determines how much of an outline or bezel can be applied to a font? The fonts that come with TMP work great, but I set up another font and both outline and bevel are very very thin even at max thickness. Is that controlled by a setting in Font Asset Creator, or is it somehow inherent in the font file itself?
     
  42. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    You should be able to change the TMP-Text the same as both of those properties are identical. I already have users who have been using it with PlayMaker. I don't have PlayMaker myself so I can't test it but it should work. We just need to figure out why you are getting that behavior on your end. Like I said those two properties are the same so it should work the same.
     
  43. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    The padding on the font controls the range of the amount of outline, dilation, glow, etc. If your font is 512 X 512 then a padding value of 5 is the normal. Padding of 8 would be a lot more. If the font is 1024 X 1024 (which is really needed unless the font contains high frequency / sharp changes) then a padding of 10 would be the same as the 5 and 16.

    Play with those and that should work fine. In terms of Outline, keep in mind that it is added at the edge of the font and thus grows inward and outward. Therefore, in order to preserve the surface area of the face, you may have to use Dilation. (that is a trick I used).
     
  44. LampRabbit

    LampRabbit

    Joined:
    Jan 31, 2013
    Posts:
    30
    @Smolli
    Use the set property action OR drag the text component onto the playmaker state window to create the set property action, from there you can set the text etc. One limitation is setting text color which should be available in the next release (correct me if I'm wrong Stephan B)
     
  45. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    You are correct as I have switched over from Color32 to Color.
     
  46. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    New Text Alignment Rich Text Tags
    Just added a new type of Rich Text Tags which provide control of text alignment within the body of the text. The new tags are as follows:
    <align=left>
    <align=center>
    <align=right>
    <align=justified>
    </align>



    P.S. Everyone say thank you to @Seith for requesting this feature :)
     
    AcidArrow likes this.
  47. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Here is a nicer example combining several Rich Text Tags like <align> <color=blue> <size=%xx.x> <i>

     
  48. Stephan-B

    Stephan-B

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    ScrollRect + UI Mask + TextMeshPro's Soft Mask in Unity 4.6
    This is still work in progress but it will be possible to have soft masking using TextMesh Pro in Unity 4.6.



     
  49. Smolli

    Smolli

    Joined:
    Mar 12, 2014
    Posts:
    84
    Funny, I first did the first method (tried it again) and I didn't have access to the same properties as when I drag the component like you suggested. There is a difference with the object-type and I can't change it afterwards. First one in drag and drop, second is through set property.
    Unity-Playmaker-TMP-01.jpeg
     
  50. Smolli

    Smolli

    Joined:
    Mar 12, 2014
    Posts:
    84
    Oh and yes, thanks @Seith for this great idea and thanks @Stephan B for the implementation and all the other stuff you do!
     
Thread Status:
Not open for further replies.