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.

TextMesh Pro Updating text on TextMeshPro causes performance spikes

Discussion in 'UGUI & TextMesh Pro' started by Fufeer, Nov 11, 2022.

  1. Fufeer

    Fufeer

    Joined:
    Jan 2, 2020
    Posts:
    5
    I have seen other posts mentioning similar issues when moving TMP components, but I have not really been able to solve it myself, and it is affecting the performance on lower-end mobile devices.

    Whenever I am updating a TextMeshPro - Text (UI) component during an Update call, the profiler shows a pretty severe spike in performance, calling
    TextMeshProUGUI.Rebuild()
    . In my case, I am updating different GameObjects that show an Enemy HP in several places on the screen, and therefore I have 9 GameObjects updating their text on every hit the enemy takes. I am aware that having different GameObjects with TMP components is not the most performant idea, but I imagine that 9 TMP components are not that big of a component count either.
    For reference, all of these components live inside the same canvas, and their position is not being changed when the text change happens. The TMP component is not set to Auto-Size either, so nothing should really be affecting the Rect Transform of the GameObject, as far as I know.

    In the picture from the profiler you can see in brighter blue the performance spikes that happen when the TMP components are Updated. The severity here doesn't seem to be much, because it is running on a high-end device, but the performance on worse phones seems to be noticeably affected by this. I am also aware that the performance shown in the Profiler while Deep Profiling is worse than that on a non-development build, but it is still noticeable as a player that the performance is worse if these components are being updated.

    upload_2022-11-11_13-20-14.png

    Has anyone had a similar issue, and experience on how to deal with it? Is it something I just have to live with? I could find work-arounds that would satisfy, since that is not the most important part of the game either, but it would be nice if I could find any fix that works.
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    Are all of these text objects under the same Canvas or multiple canvases?

    Are you using Layout components like Vertical Layout Groups or Horizontal Layout Groups?

    Are the RectTransform of these text objects set to stretch mode?
     
  3. Fufeer

    Fufeer

    Joined:
    Jan 2, 2020
    Posts:
    5
    All of these GameObjects are living under the same parent Canvas.

    I am not using Layout Groups, although I am using a Canvas Group for them. However, removing it did not seem to help at all.

    The RectTransform of these objects are not set to Stretch Mode. I did notice that they were living under a GameObject that indeed did have its RectTransform set to Stretch Mode, and I changed it back to default mode. However, this didn't improve performance in any way, as the TextMeshProUGUI.Rebuild() functions were still being called.

    In case it is any helpful, this is the hierarchy of the UI in my game. The selected GameObjects are the ones that have a TMP component attached.
    upload_2022-11-14_16-49-12.png
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    What are all these shadow objects?

    Can you post an Inspector screenshot of one of those?

    Can you also post an Inspector screenshot of one of the text object where I can see all the settings set on that text object? I presume all text objects have the same settings. Correct?
     
  5. Fufeer

    Fufeer

    Joined:
    Jan 2, 2020
    Posts:
    5
    All those gameobjects are displaying the same text, with a slightly different transform position. This was done in order to simulate a pixel perfect outline, since we didn't have time to implement one yet and TMP apparently doesn't have one either.

    You are correct in that all of these GameObjects have the same settings. They look like this:
    upload_2022-11-25_17-29-20.png upload_2022-11-25_17-30-5.png
    Is there any parameter that looks wrong to you?
     
  6. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    Have you tried using SDF instead of a bitmap font? At lower sampling point size, the SDF will have slightly rounded corners but the outline will be free as it will only require one text object. Increasing the sampling point size would also improve the rendering fidelity and lessen those rounded corners where at small point size those might not be visible anyway.

    Alternatively, instead of using 8 additional text objects, you could take a look at the "Animating Vertex Attribute" example scene and related scripts and create a similar script that would duplicate the necessary geometry to create this bitmap shadow FX. This would save you 8 potential text parsing and layout passes.
     
  7. Fufeer

    Fufeer

    Joined:
    Jan 2, 2020
    Posts:
    5
    Thanks for all the recommendations, I will give them a try. However, don't you think that it is worrisome that a relatively small amount of text objects updating is causing performance drops?
     
  8. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    I would suggest re-profiling this in a debug build but without Deep Profiling as the reported values in deep profile will be way off the mark.