Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more..
    Dismiss Notice
  3. Dismiss Notice

TextMesh Pro How can I stop TMP rebuilding ? (performance)

Discussion in 'UGUI & TextMesh Pro' started by Ekincan, Jul 8, 2021.

  1. Ekincan

    Ekincan

    Joined:
    Sep 8, 2015
    Posts:
    57
    My problem is that my TextMeshs are rebuilding all the time.
    I want to simply disable auto-rebuilding or switch it to a manual building if possible.

    I created this Damage Numbers asset and I want to improve the performance.
    After a number is spawned the TMP component is left untouched, the transform is moved and stuff but that would work without rebuilding the mesh too.

    Would appretiate help a lot.
     
  2. Ekincan

    Ekincan

    Joined:
    Sep 8, 2015
    Posts:
    57
    Also if there was a way for me to make a disabled textmeshpro generate it's mesh (manually) and keep the mesh even though it is disabled that would also work.
     
  3. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    If you are only moving the text objects around, that should not trigger a rebuild.

    but you said "moved and stuff" so can you provide more insight on what "stuff" is? If you are also changing some of the text properties, those could trigger a rebuild.

    Are you using the normal <TextMeshPro> component or the <TextMeshProUGUI> with UGUI?

    If you are using the UGUI component, do you have layout component in there?
     
  4. Ekincan

    Ekincan

    Joined:
    Sep 8, 2015
    Posts:
    57
    I am using the textmeshpro (no canvas) component.
    After looking more into it, I think one thing that may have triggered rebuilds could have been changing textmeshpro's alpha.

    I did find a solution.
    I enable TMP, update it's mesh, copy the mesh into 2 other objects with meshrenderers and disable TMP again.

    Changing the colors in the mesh directly seems to be decent performance-wise.

    Let me know if you have a more elegant solution.
    Otherwise you can consider this solved :)
     
  5. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    505
    @Stephan_B Hey Stephan, I stumbled on this thread and I have been seeing similar behavior as well, where changing the alpha or color property on the TextMeshPro (not the UGUI counterpart) will cause the text to rebuild. Is there a way to solve this?
     
    Last edited: May 11, 2022
  6. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    505
    I see that in the source code, whenever the color property is changed, everything has to be rebuilt. For now I'll try to reduce the amount of text to be animated for now, but I expect the mesh to just simply update its vertex colors instead of rebuilding everything.
     
  7. AllanGameSmithing

    AllanGameSmithing

    Joined:
    Aug 10, 2022
    Posts:
    11
    Hey, I just stumbled upon this thread as well... I have a "scrolling combat text" system, at first it was canvas based with tons of texts, following entities and what not.... and despite a ton of things going on in the game, it is one of the heaviest things in the game. I imagined this could become a problem and an area to optimise, so I thought "I'll remake the system, without canvases, just the 3D text mesh pro component", but I was surprised to find that it became even slightly heavier than before.

    I noticed the rebuilds and was a bit intrigued since the text itself doesnt change... then here I learned that the .alpha property is triggering the rebuild, checked the code and yeah, clear as day. Is there any way to use TMP 3d texts, and be able to change the color and alpha... without triggering rebuilds? Changing my code to use transform scale animation instead of alpha caused a considerable performance boost!
     
    Last edited: Oct 9, 2022
    ImproxGames likes this.
  8. Ekincan

    Ekincan

    Joined:
    Sep 8, 2015
    Posts:
    57
    Hey,

    In my "Damage Numbers Pro" asset, I actually worked around that problem by modifying the vertex colors of the generated mesh directly.
    I make TMP generate 1 mesh, copy it into my mesh renderers and from there I simply change the vertex colors of the mesh.

    It was a bit complicated but it improved the performance of my asset by a lot.
    Hopefully this helps you improve your systems too.

    Cheers.
     
    AllanGameSmithing likes this.
  9. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    The most efficient to modify the color of the text is indeed modifying the vertex colors of individual characters as opposed to forcing a whole new text layout pass just to change the colors.

    Take a look at the examples included in the TMP Examples & Extras and more specifically the Animating Vertex Attributes and the related scripts which shows an example of this.
     
    AllanGameSmithing and Ekincan like this.