Search Unity

TextMesh Pro Can't modify TMPro's vertices during <size> tag

Discussion in 'UGUI & TextMesh Pro' started by bonickhausen, Apr 24, 2018.

  1. bonickhausen

    bonickhausen

    Joined:
    Jan 20, 2014
    Posts:
    115
    Hi.

    I made a simple script to offset a few TMProUGUI characters.

    Code (CSharp):
    1. if (i == _currentLetter)
    2.             {
    3.                 destinationVertices[vertexIndex + 0] = sourceVertices[vertexIndex + 0] + offset;
    4.                 destinationVertices[vertexIndex + 1] = sourceVertices[vertexIndex + 1] + offset;
    5.                 destinationVertices[vertexIndex + 2] = sourceVertices[vertexIndex + 2] + offset;
    6.                 destinationVertices[vertexIndex + 3] = sourceVertices[vertexIndex + 3] + offset;
    7.             }
    8.             else if (i == _currentLetter - 1)
    9.             {
    10.                 destinationVertices[vertexIndex + 0] = sourceVertices[vertexIndex + 0] + halfOffset;
    11.                 destinationVertices[vertexIndex + 1] = sourceVertices[vertexIndex + 1] + halfOffset;
    12.                 destinationVertices[vertexIndex + 2] = sourceVertices[vertexIndex + 2] + halfOffset;
    13.                 destinationVertices[vertexIndex + 3] = sourceVertices[vertexIndex + 3] + halfOffset;
    14.             }
    It works perfectly EXCEPT for when I have text surrounded by <size=150%> tags.

    What am I doing wrong?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Without knowing when / how you are modifying the vertices, it is hard to provide more insight.

    For instance, are you trying to modify the vertices after the text object has been generated similar to how it is done in the VertexJitter.cs script included in the Examples & Extras/scripts folder?
     
  3. bonickhausen

    bonickhausen

    Joined:
    Jan 20, 2014
    Posts:
    115
    Thank you for the fast reply!

    This is the whole method:

    Code (CSharp):
    1. void TextEffect()
    2.     {
    3.         if (_currentLetter >= _currentText.Length) return;
    4.  
    5.         Text.ForceMeshUpdate();
    6.  
    7.         TMP_TextInfo info = Text.textInfo;
    8.  
    9.         int charCount = info.characterCount;
    10.  
    11.         TMP_MeshInfo[] cachedMeshInfo = info.CopyMeshInfoVertexData();
    12.  
    13.         Vector3 offset = Vector3.up * TextFXBump;
    14.  
    15.         Vector3 halfOffset = offset / 2;
    16.  
    17.         for (int i = 0; i < charCount; i++)
    18.         {
    19.             if (!info.characterInfo[i].isVisible) continue;
    20.  
    21.             int vertexIndex = info.characterInfo[i].vertexIndex;
    22.  
    23.             int materialIndex = info.characterInfo[i].materialReferenceIndex;
    24.  
    25.             Vector3[] sourceVertices = cachedMeshInfo[materialIndex].vertices;
    26.  
    27.             Vector3[] destinationVertices = info.meshInfo[materialIndex].vertices;
    28.  
    29.             if (i == _currentLetter)
    30.             {
    31.                 destinationVertices[vertexIndex + 0] = sourceVertices[vertexIndex + 0] + offset;
    32.                 destinationVertices[vertexIndex + 1] = sourceVertices[vertexIndex + 1] + offset;
    33.                 destinationVertices[vertexIndex + 2] = sourceVertices[vertexIndex + 2] + offset;
    34.                 destinationVertices[vertexIndex + 3] = sourceVertices[vertexIndex + 3] + offset;
    35.             }
    36.             else if (i == _currentLetter - 1)
    37.             {
    38.                 destinationVertices[vertexIndex + 0] = sourceVertices[vertexIndex + 0] + halfOffset;
    39.                 destinationVertices[vertexIndex + 1] = sourceVertices[vertexIndex + 1] + halfOffset;
    40.                 destinationVertices[vertexIndex + 2] = sourceVertices[vertexIndex + 2] + halfOffset;
    41.                 destinationVertices[vertexIndex + 3] = sourceVertices[vertexIndex + 3] + halfOffset;
    42.             }
    43.         }
    44.  
    45.         for (int i = 0; i < info.meshInfo.Length; i++)
    46.         {
    47.             info.meshInfo[i].mesh.vertices = info.meshInfo[i].vertices;
    48.             Text.UpdateGeometry(info.meshInfo[i].mesh, i);
    49.         }
    50.     }
    It is being called in LateUpdate.

    Also called in LateUpdate is a function that changes the TextMeshProUGUI's Text. So, it is safe to say that the text is being changed every LateUpdate.

    My TextMeshProUGUI is being "fed" the text. This is what I'm talking about:



    I am also calling
    Text.ForceMeshUpdate()
    at Start().

    Other than that, I am not modifying the TextMeshProUGUI in any other way.

    Funny thing is, my effect works perfectly EXCEPT for when the text gets tagged.

    Imagine I have a TMProUGUI with the following sentence:

    "This is a test. Yellow car blue car <size=150%>green car</size> pink car"

    Because the way the text is being "fed" to the UI display, the effect will work perfectly up until "green car". As soon as the tag on "green car" is activated, the whole text loses the effect. Closing the tag won't help either and because of this, pink car is never moved by my script.

    Got any clues? I can provide you with more information if necessary.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I'll try taking a look later this afternoon or tonight. I'll provide feedback as soon as I have more information.
     
  5. bonickhausen

    bonickhausen

    Joined:
    Jan 20, 2014
    Posts:
    115
    Thank you!

    I can send you the project folder if you wish, just say the word.
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    That would be great via a PM just in case you have stuff you don't want to share publicly.
     
  7. bonickhausen

    bonickhausen

    Joined:
    Jan 20, 2014
    Posts:
    115
    Hi there!

    Have you by any chance found a fix for this?