Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Bug Failing to change TMP mesh colors for fallback font asset

Discussion in 'UGUI & TextMesh Pro' started by gnikwehttam, Sep 27, 2022.

  1. gnikwehttam


    Sep 27, 2022
    Using TMP Version 3.0.6
    Using Unity 2021.3.6f1

    I've been trying to get other languages localized in my game. Which upon adding languages that used the Cyrillic Alphabet, I've used a fallback font for my primary font asset. However, when characters are used from the fallback font asset, the color changing of the mesh no longer works

    The TMP text object at runtime as the color changes, the primary text being updated with a gradient color

    I would expect that the Cyrillic text should also be changing color like the "Testing" characters above.

    TextMeshPro Object from above screenshot

    Code for Updating Mesh Color:

    Method called in Update() Function
    _textComponent is the TMP_Text object
    _initialColor is default color of the text
    _gradientFill is a custom color gradient object to create an ever changing text coloration

    Code (CSharp):
    1.     private void UpdateColor(bool reset = false)
    2.     {
    3.         Mesh mesh = _textComponent.mesh;
    4.         Color[] colors = mesh.colors;
    5.         Vector3[] vertices = mesh.vertices;
    7.         _textComponent.ForceMeshUpdate();
    8.         mesh = _textComponent.mesh;
    9.         vertices = mesh.vertices;
    11.         for (int i = 0; i < _textComponent.textInfo.characterCount; i++)
    12.         {
    13.             TMP_CharacterInfo c = _textComponent.textInfo.characterInfo[i];
    15.             int index = c.vertexIndex;
    17.             colors[index] = reset ? _initialColor : _gradientFill.Evaluate(Mathf.Repeat(Time.time + vertices[index].x * 0.001f, 1f));
    18.             colors[index + 1] = reset ? _initialColor : _gradientFill.Evaluate(Mathf.Repeat(Time.time + vertices[index + 1].x * 0.001f, 1f));
    19.             colors[index + 2] = reset ? _initialColor : _gradientFill.Evaluate(Mathf.Repeat(Time.time + vertices[index + 2].x * 0.001f, 1f));
    20.             colors[index + 3] = reset ? _initialColor : _gradientFill.Evaluate(Mathf.Repeat(Time.time + vertices[index + 3].x * 0.001f, 1f));
    21.         }
    23.         mesh.vertices = vertices;
    24.         mesh.colors = colors;
    25.         _textComponent.canvasRenderer.SetMesh(mesh);
    26.     }
    If I change the (primary) Font Asset of the TextMeshPro text to the fallback font asset it works fine for the Cyrillic letters only. it fails only when the primary fontasset needs to use letters from the fallback asset and still only fails for the letters from the fallback font asset.

    I've listed this as a bug as it seems to work for both font assets independently but not when one is used as a fallback font asset.

    I apologize if this has been asked, I looked through the forums for a similar post, and the closest thing I could find was this:
    but it did not appear to resolve my issue.
  2. Stephan_B


    Feb 26, 2017
    Quick and short reply as I am traveling.

    When a fallback is used, the geometry of the fallback is in a different mesh. In the textInfo you have an array of meshInfo which contain the geometry of each individual mesh.

    when you query textInfo.materialCount, this tells you how many mesh the text object is using. So if the text object has a fallback, then you will have two mesh where you need to iterate over the vertex colors as well to modify them.

    i believe in the TMP Examples & Extras in the Animating Vertex Attribute example scene and relevant script, the vertex color cycling script would show an example of this.

    sorry for the short reply. Hopefully this gives you the information you need.
  3. gnikwehttam


    Sep 27, 2022
    Thank you Stephan_B, I was able to resolve my issue.