CPU Hitches GeneratingTextMesh

Unity 2019.3.1
TMP 2.1.0-Preview8

I’m trying to render a prefab that contains a maybe a 9 text mesh pro labels to a texture. The downside is that I seeing two frames of pretty expensive TMP operations to generate the mesh that I’m wondering if there’s a way to get around. The labels I’m using are not UGUI TextMesh Pro labels as these labels exist in world space and are rendered by a camera that is culled to only render the labels.

The first frame is when we instantiate the prefab that contains the large amount of text. I needed to deep profile in order to get the call stacks (I’m aware of the overhead, but from what I can gauge it is also what is causing the hitch in play mode).

Note that the time isn’t spent allocating the buffers for the arrays, but rather generating text because as I mentioned the text is very long (paragraphs of text). The next frame when I try to render a disabled camera to texture using Camera.Render() I’m getting another hitch as it regenerates the mesh data again for the camera render for the exact same labels.


The result is that there is a significant frame rate drop due to these subsequent long frames of calculation. I think I’d be OK with one frame, but the fact that this mesh is being generated twice when the text hasn’t changed is concerning me.

Another interesting thing is that while there are only 19 calls to TextMeshPro.Rebuild there are 136 calls to GenerateTextMesh! Is there maybe some duplicate calls to force rebuild the mesh in the code?

If anyone has any tips to avoid this I’d appreciate it.

How much text do these text objects contains? Ie. rough number of characters?

Are you using any layout components that would affect these text objects?

I found the likely culprit, it was some labels had a max size of 1000 on auto-size labels. After changing the max size to something more reasonable the hitch is much more manageable. I am still curious on why it would need to do this twice, if I get time I will look into it later. Sorry about the false alarm.

Just keep me posted.

Auto-size is an iterative process so you need to be mindful of that. I do not recommend having auto-size enabled on more than one object within a group of size like objects. See the following post for what I mean and suggestions on a much more efficient way to handle this.