Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

TMP Problem: when you move, the text is updated

Discussion in 'UGUI & TextMesh Pro' started by BeginnerPolymath, Jun 27, 2020.

  1. BeginnerPolymath

    BeginnerPolymath

    Joined:
    Jul 31, 2015
    Posts:
    38
    I use color changes of specific characters as in this lesson
    but I also use my own font that creates SubMeshUI and I think that when I change Transform it is updated and repainted with the original color. With fonts that do not use SubMesh there is no such problem.

    Video demonstration of the problem

    Maybe there's some way you can give up SubMesh, but I don't know what he's responsible for.
     
  2. BeginnerPolymath

    BeginnerPolymath

    Joined:
    Jul 31, 2015
    Posts:
    38
    I realized it was because of the large number of characters in the font, but is there any way to change it? To make sure that SubMesh doesn't update when it moves?
     
  3. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    When changing colors, are you checking the MaterialIndex of each character to determine in which MeshInfo they are contained?

    Take a look at the VertexJitter.cs script which does that.
     
  4. BeginnerPolymath

    BeginnerPolymath

    Joined:
    Jul 31, 2015
    Posts:
    38
    I use a similar code on VertexJitter.

    My Code
    Code (CSharp):
    1. public void ChangeColorChars (int pageID, int stepID, Color32 color)
    2. {
    3.     for (int i = spritzScript.Pages[pageID].Steps[stepID].First; i <= spritzScript.Pages[pageID].Steps[stepID].Last; ++i)
    4.         {
    5.             if(m_TextMeshPro.textInfo.characterInfo[i].character != ' ' || m_TextMeshPro.textInfo.characterInfo[i].character != '\t' || m_TextMeshPro.textInfo.characterInfo[i].character != '    ')
    6.             {
    7.                 int meshIndex = m_TextMeshPro.textInfo.characterInfo[i].materialReferenceIndex;
    8.                 int vertexIndex = m_TextMeshPro.textInfo.characterInfo[i].vertexIndex;
    9.          
    10.                 Color32[] vertexColors = m_TextMeshPro.textInfo.meshInfo[meshIndex].colors32;
    11.                 vertexColors[vertexIndex + 0] = color;
    12.                 vertexColors[vertexIndex + 1] = color;
    13.                 vertexColors[vertexIndex + 2] = color;
    14.                 vertexColors[vertexIndex + 3] = color;
    15.             }
    16.          
    17.         }
    18.  
    19.         m_TextMeshPro.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
    20.     }
    But I decided to check if Jitter would work when moving if I had SubMesh present and it was not working when moving.
     
  5. BeginnerPolymath

    BeginnerPolymath

    Joined:
    Jul 31, 2015
    Posts:
    38
    I temporarily fixed it by reducing the number of characters in the font.
     
  6. BeginnerPolymath

    BeginnerPolymath

    Joined:
    Jul 31, 2015
    Posts:
    38
    Okay, I don't know what the connection between my generated font and the original LiberationSans font was, but after LiberationSans was removed, SubMesh stopped showing up and the problem disappeared.
     
  7. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Sub mesh objects are used whenever a fallback font asset or sprite asset is used.

    For instance, if you primary font asset is missing some characters, TMP would search any potential local and global fallbacks for the requested character and if found in one of the fallbacks, then a sub mesh would be created for this character.

    You moving code probably doesn't handle this correctly.
     
  8. BeginnerPolymath

    BeginnerPolymath

    Joined:
    Jul 31, 2015
    Posts:
    38
    I do have my own ScrollView system, but even if I use the original UnityUI ScrollView and Text has SubMesh, JitterText does not work. Apparently, the transformation updates the mesh and recreates SubMesh again. As for me, the easiest solution would be to be able to turn off the search for missing characters.
     
  9. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    What version of the TMP package are you using?

    In the latest Preview releases of TMP, I added special handling to get around potential rounding errors in the calculation of the RectTransform size when using Stretch Anchoring modes where although the size of the RectTransform doesn't change, the OnRectTransformDimensionsChange is called due to rounding errors.

    I suspect, the vertex jitter might be trigger as a result of this.
     
  10. BeginnerPolymath

    BeginnerPolymath

    Joined:
    Jul 31, 2015
    Posts:
    38
    I'll use the last 14 preview version 2.1.0.