Text vertices not updating for TextMeshProUGUI

I got this simple script working fine with TextMeshPro following this tutorial, but TextMeshProUGUI completely ignores the vertices pushed to TextMeshProUGUI.mesh.vertices.

  IEnumerator Animate()
  {
    var TMPtext = GetComponent<TextMeshProUGUI>();

    TMPtext.ForceMeshUpdate();
    Vector3[] vertices;
    Matrix4x4 matrix;

    for (int i = 0; i < TMPtext.textInfo.characterCount; i++)
    {
      var vert = TMPtext.textInfo.characterInfo[i];

      if (!vert.isVisible)
        continue;

      vertices = TMPtext.mesh.vertices;
      var vertexIndex = vert.vertexIndex;

      matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, 30f), Vector3.one);

      var pos = transform.position;

      vertices[vertexIndex + 0] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 0]);
      vertices[vertexIndex + 1] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 1]);
      vertices[vertexIndex + 2] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 2]);
      vertices[vertexIndex + 3] = matrix.MultiplyPoint3x4(vertices[vertexIndex + 3]);

      TMPtext.mesh.vertices = vertices;

      yield return new WaitForSeconds(0.1f);
    }
  }

These are the components on the GameObject:

Here’s a video sample of this code running.

What am I doing wrong?
Any pointers are much appreciated! :face_with_spiral_eyes:

With the Canvas system, you need to push the updated mesh to the canvas renderer.

To do that you can either use the CanvasRenderer.SetMesh() function or the TMP_Text.UpdateGeometry(mesh, meshIndex). Take a look at some of the TMP example scripts like VertexJitter.cs included in the TMP Examples & Extras as these all use this UpdateGeometry function.

1 Like

Thank you!
Adding canvasRenderer.SetMesh(TMPtext.mesh); or alternativelyTMPtext.UpdateGeometry(TMPtext.mesh, 0); after TMPtext.mesh.vertices = vertices worked like a charm! <3