Issue with TextMeshProUGUI.Rebuild()

Hello, please help with some issues with unity UI events and TextMeshPro
I have container with text items without layout groups but in content container in Scroll Rect
Hierarchy:

  • Canvas

  • Canvas Group

  • Scroll Rect

  • Viewport(with mask)

  • Content

  • TextMeshProUGUI [25-40 objects]

And when i moving canvas group object just change anchor position, i get this(Deep Profile):


I think it happens because when i move parent object Unity Event System calls OnRectTransformDimensionsChange() and TMP rebuilds layout. But how to get around this ?

Unity Version: 2019.2.4f1
TMP Version: 2.0.1 (from Package Manager)

2 Likes

This is a long standing issue with the RectTransform that I believe is due to precision / floating point issue where although the size of the RectTransform has not changed, it thinks that it has thus forcing a full update of everything / child of the Canvas.

This mostly occurs when using Stretch mode on the RectTransform or someone in that hierarchy. It is also susceptible to position values like 1.4331 instead of something like 1.45 where those extra decimal places cause the issue.

This issue is one of the reasons why in some users report bad performance on the ScrollRect while other don’t as it is based on those rounding errors in the calc of the offset position of the RectTransform.

See if you can re-work how those are setup to avoid these potential rounding errors.

2 Likes

Thanks, i found solution and problem in my hierarchy on root canvas has been activated option PixelPerfect and as consequence precision issue on child RectTransform. PixelPerfect isn’t perfect.

P. S. Thanks for TextMeshPro. :wink:

3 Likes

I am facing this issue and the above solutions didn’t work for me. I am using Unity 2019.3.0f6. I have a canvas for one UI screen which I show it in worldspace. It holds around 15 TextMeshProuGUI components and few image components. When the screen is enabled that initial few frames I could see a very big performance hit. It is happening each time I enable that screen. Can anyone provide me a solution to get a seamless gameFlow without any perfomance hit ?

1 Like

Do you know if there exists a (internal) bug-report for this issue and it gets fixed eventually? If no ticket exists, do you mind to create one?

Having the same issue and still looking for a solution, takes 45.5 ms to Rebuild TextMeshProUGUI on OnEnable of a UI popup. Hope there is a simple solution which we haven’t noticed yet. Using Unity 2019.3.0

Do your text objects all have auto-size on them?

Does the hierarchy have layout components?

How many characters does the text contain?

All these things can have an impact where OnEnable won’t have much impact to a lot more.

Also be sure to test in a build as there are many events related to Editor stuff that only happen in the Editor but not a build.

Please always feel free to submit a bug report with the included project for me to take a closer look.

Disabling autosize fixed the spike for me but we need it for localized texts, is there any option to use autosize without this huge spike?

See the following post which outlines how I recommend using auto-size.

P.S. I will (once I get a chance / have time) revisit Enabling / Disabling objects to look for potential improvements. I am also working on several other performance improvements but most of them will come from the new TextCore which TMP will use under the hood when it is ready. Ie. improvements will keep coming over time.

3 Likes