TMP resizing rect transform scale in code

So whenever I resize the scale of a rect transform in code, and a child or the game object contains a TextMesh Pro component, the text just disappears, what is going on? and is there a way to fix this?

In which version of Unity and TextMesh Pro are you observing this behavior?

Can you provide me with a script that I can add to a text object to test this out?

I’m using Unity: 2019.1.4f1
For textmesh pro: 2.0.1

I’m pretty much just interpolating from a scale 0 to scale 1 for a little animation for UI with something like this

private Vector3 maximumScale;
private Vector3 minimumScale

// Update is called once per frame
protected void Update()
{
if (timerActive)
{
transform.localScale = Vector3.Lerp(minimumScale, maximumScale, timePassed);
UpdateTimer();
}
}

Make sure the scale is uniform. Ie. X, Y and Z all have to have the same value.

If the issue persists, please provide me with a simple repro scene / project or if easier just submit a bug report with the include repro project and then provide me with the Case #.

I should be able to look at this today if you can get me a project / scene or something.

P.S. I realize that asking for a repro scene / project requires additional investment of your time. My apologies for that.

I most certainly want to help you (all users) resolve potential issues and given I have been totally slammed lately (so much to do / so little time) providing these repro projects / bug reports make it so much easier for me and helps ensure I can quickly reproduce the potential issue, figure out what is going and ultimately resolve the issue and get you back to working on your stuff :slight_smile:

It works when the Canvas Render mode is on Screen Space - Overlay, but not in Screen Space - Camera.

That is strange. Now I really need some simple scene / repro for this.

Sorry my bad, I meant world space

Edit: Here’s a scene with it, the script isn’t active which is on the image
https://www.dropbox.com/s/qoj0ixsy0lbs65s/TextMeshPro Bug.zip?dl=0

Thank you for providing the project for me to look at.

As I suspected, the issue is related to the use of non uniform scale where the Z scale remains at Zero which results in the text object not being visible.

Change your initialScale to use a Vector3 instead of Vector2 as this results in the Z scale remaining at Zero.

In order for the text to render correctly, scaling information is passed to the shader via the vertex attributes. Having Z at zero makes for unhappy text.

Thank you for your help

1 Like