Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

[TextMeshPro] Animating the alpha of a textmesh.. and more

Discussion in 'UGUI & TextMesh Pro' started by Sandler, Dec 17, 2017.

  1. Sandler

    Sandler

    Joined:
    Nov 6, 2015
    Posts:
    249
    Hi, im kinda confused right now (i love textmeshpro but im running in some very strange problems).

    Im showing lots of text dynamically. Meaning i drop stats like "+1", "+5", "Nice!" etc. I pooled 10 text fields for that.
    I switched to textmeshpro cause setting the normal text always caused a hiccup (canvas.sendwillrendercanvas and rebuild text)... and that .. did not work as planned. (Im using Unity 5.6.0f4 and TextMeshPro-1.0.55.56.0b11)

    I just wanted to set a textboxes value (a textmeshpro meshrenderer) , like "+1" fade it in and fade it out. The problem is, how can i do that without triggering garbage collection or cpu or textmeshpros.Rebuild() function. How can i drop such messages as fast as possible? (Setting the text causes lag & animating the vertex color causes lag^^)

    Do i have to predefine all possible texts? (Like 10 x "+1" textboxes. 10 x "+2" textboxes, "Nice!")
    How can i fade in (setting its alpha value) a textmeshpro textfield without triggering the textmeshpros.Rebuild() function in the TMP_UPdateManager.OnCameraPreRenderer method?
    Do i have to animate the material propertys for that?

    Maybe i just got some bugging or old version, as im reciving following warning:
    Character with ASCII value of 32 was not found in the Font Asset Glyph Table. It was replaced by a space.
    But i have ascii value 32 - space - in the glyph info?

    I just upgraded TextMeshPro-1.0.55.56.0b11.dll files via the assetshop, this caused textmeshpro scripts stop working (script has an error in the dll blabla, but no log message showing up). After copying old files back (smart me) all inspector textmeshpro config was lost... yeah god thanks humanity invented beer^^ looks like ill upgrade to 2017. Please help^^
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Whenever you change the content of the text, the underlying geometry has to be regenerated but unless you have 100's of text objects all being updated at once, this should not be an issue.

    Whenever you change a string or concatenate a string and given strings are immutable, you will get garbage collection.

    Doing something like this will result in GC.
    Code (csharp):
    1. m_TextComponent.text = "You earn "  + numCoins + " coins!";
    Instead you can use the TMP_Text.SetText() function which allows you to combine strings and variables without GC.
    Code (csharp):
    1. private string m_Message_01 = "You earn {0} coins!";
    2.  
    3. // Then somewhere in your code...
    4. m_TextComponent.SetText(m_Message_01, numCoins);
    Take a look at the example scene "Benchmark (Floating Text)" which displays lots of changing numbers which also fade over time.

    In terms of the upgrade issues, please see the following post which also references the top sticky post in this section of the user forum.
     
    Last edited: Dec 17, 2017
  3. Sandler

    Sandler

    Joined:
    Nov 6, 2015
    Posts:
    249
    The problem was some kind of bug with the old unity version (Character with ASCII value of 32 was not found in the Font Asset Glyph Table. It was replaced by a space.). After upgrading tpp 2017 this message disappeared.

    And i learned something: Using deep profile causes a strong slowdown. Thanks for the Benchmark hint, got it up running at its very fast. Awesome job!
     
    Stephan_B likes this.