Search Unity

Question Shake Text Dont Work When Text Is Bold - Text Mesh Pro

Discussion in 'UGUI & TextMesh Pro' started by Ceneu, Mar 23, 2024.

  1. Ceneu

    Ceneu

    Joined:
    May 20, 2022
    Posts:
    2
    Hey guys, I have a script that makes my text vertices shake, and when I make the text bold the shake effect just stops.

    Here is the code I am using to make my text shake:

    Code (CSharp):
    1. if (Dialogs[index].isToShake)
    2.         {
    3.             dialogText.ForceMeshUpdate();
    4.             mesh = dialogText.mesh;
    5.             vertices = mesh.vertices;
    6.            
    7.             for (int i = 0; i < dialogText.textInfo.characterCount; i++)
    8.             {
    9.                 TMP_CharacterInfo c = dialogText.textInfo.characterInfo[i];
    10.  
    11.                 int index2 = c.vertexIndex;
    12.  
    13.                 Vector3 offset = Wobble(Time.time + i);
    14.                 vertices[index2] += offset;
    15.                 vertices[index2 + 1] += offset;
    16.                 vertices[index2 + 2] += offset;
    17.                 vertices[index2 + 3] += offset;
    18.             }
    19.  
    20.             mesh.vertices = vertices;
    21.             dialogText.canvasRenderer.SetMesh(mesh);
    22.         }
    23.  
    24.     Vector2 Wobble(float time)
    25.     {
    26.         return new Vector2(Mathf.Sin(time * 70f), Mathf.Cos(time * 70f));
    27.     }
    How can I make work properly?
     

    Attached Files:

  2. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    846
    try calling
    dialogText.ForceMeshUpdate();
    again after SetMesh, the bold effect probably overrides your vertices
     
  3. Ceneu

    Ceneu

    Joined:
    May 20, 2022
    Posts:
    2
    Hey Xucian! Thank you for the reply, but still doesnt work.
     
  4. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    846
    I can take a wild guess that doing it in LateUpdate might work

    but the ultimate solution is diving into TMPro's own code and see where does it apply the bolding code. maybe you can hook into that and apply your own code, after it

    or if there's no way to interact with it from the inside, you're left with modifying TMPro itself. I imported TMPro as a regular asset (or as a local package, IIRC, don't have access to the code right now), so I can edit and git-version those changes (on another branch for later reference), but ofc that's almost like a 'lifetime' contract where you might not upgrade to new versions that easily