Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

TextMesh Pro `TextMeshPro_UGUI` doesn't update on `string.Empty`

Discussion in 'Unity UI & TextMesh Pro' started by Creta_Park, Oct 8, 2018.

  1. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    22
    I wrote the code to copy the mesh data and write text animations.

    And I was working on replacing TMP with UGUI in order to convert from world space to Canvas space.

    However, there was a problem in TextMeshPro_UGUI that it worked fine in TextMeshPro.

    Setting the text property to string.Empty does not change what is displayed.

    I am wondering what the difference is, and I am looking for a way to solve this problem.

    * TextMeshPro_UGUI
    TMP UGUI stringEmpty.png

    * TextMeshPro (for World space)
    TMP not UGUI stringEmpty.png
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,862
    How are you setting the text? Are you using the .text property or one of the SetText() variant?
     
  3. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    22
    I tried both(text property, SetText method) style, but still not work put string.Empty
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,862
    What version of TMP are you using?
     
  5. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    22
    I have using 1.3.0 (Unity version is 2018.2.6f1)
    recent.png
     
  6. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,862
    I'll try taking a look this afternoon and get back to you shortly thereafter.
     
  7. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    22
  8. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,862
    See if the following works on your end?

    Create a TextMeshProUGUI object and attach the following script to it. Make sure you reference the text object in the public field.

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using UnityEngine;
    4. using TMPro;
    5. public class SandBox_01 : MonoBehaviour
    6. {
    7.     public TMP_Text m_TextComponent;
    8.  
    9.     private void Awake()
    10.     {
    11.         StartCoroutine(ClearText());
    12.     }
    13.  
    14.     IEnumerator ClearText()
    15.     {
    16.         while (true)
    17.         {
    18.             m_TextComponent.text = "A line of text.";
    19.  
    20.             yield return new WaitForSeconds(1.0f);
    21.  
    22.             m_TextComponent.text = string.Empty;
    23.  
    24.             yield return new WaitForSeconds(1.0f);
    25.         }
    26.     }
    27. }
    28.  
     
  9. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    22


    If TMP and TMP_UGUI is pure then fine
    (nothing access from anything, just SandBox_01 component)
    But it have occurs on VertexUpdate method, CopyVertexData method has made this problem maybe i think.

    If you sure, I can share my code privatly to you in DM (or email)
     
  10. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    22
    I want to know what the cause is...
     
  11. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,862
    Best way for me to figure out why this might be happening in this case is to get a simple repro project / scene.
     
  12. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    22
    I have make it simply reproduce this.

    can use
    referenceGlyphTransform
    to change the first glyph's mesh of TMP.

    And with
    doMeshChange
    to toggle true then it's update the mesh of the first character.

    and
    doClearText
    determines whether to execute the ClearText coroutine method.

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using TMPro;
    4. public class SandBox_01 : MonoBehaviour
    5. {
    6.     public TMP_Text m_TextComponent;
    7.     private TMP_MeshInfo[] cachedDefaultMeshData;
    8.  
    9.     public Transform referenceGlyphTransform;
    10.  
    11.     public bool doMeshChange = false;
    12.  
    13.     public bool doClearText = true;
    14.  
    15.     private void Awake()
    16.     {
    17.         if (doClearText)
    18.             StartCoroutine(ClearText());
    19.  
    20.         TMPro_EventManager.TEXT_CHANGED_EVENT.Add((TMP) => {
    21.             if (!TMP)
    22.                 return;
    23.          
    24.             if (TMP == m_TextComponent) {
    25.                 cachedDefaultMeshData = m_TextComponent.textInfo.CopyMeshInfoVertexData();
    26.                 UpdateMesh();
    27.             }
    28.         });
    29.     }
    30.  
    31.     void Update()
    32.     {
    33.         UpdateMesh();
    34.     }
    35.  
    36.     void UpdateMesh()
    37.     {
    38.         if (!doMeshChange) return;
    39.         //only first glyph change position for test.
    40.  
    41.         var textInfo = m_TextComponent.textInfo;
    42.         var characterList = textInfo.characterInfo;
    43.  
    44.         if (characterList.Length >= 1) {
    45.             TMP_CharacterInfo charInfo = characterList[0];
    46.             if (charInfo.isVisible) {
    47.              
    48.                 int materialIndex = charInfo.materialReferenceIndex;
    49.                 int vertexIndex      = charInfo.vertexIndex;
    50.  
    51.                 int TL = vertexIndex + 1, TR = vertexIndex + 2,
    52.                     BL = vertexIndex,     BR = vertexIndex + 3;
    53.  
    54.                 Vector3[] sourceVertices  = cachedDefaultMeshData[materialIndex].vertices,
    55.                           currentVertices = textInfo.meshInfo[materialIndex].vertices;
    56.              
    57.                 Vector3 offset = (sourceVertices[TL] + sourceVertices[BR]) * 0.5f;
    58.  
    59.                 Matrix4x4 matrix = referenceGlyphTransform != null ?
    60.                                    Matrix4x4.TRS(
    61.                                        referenceGlyphTransform.localPosition,
    62.                                        referenceGlyphTransform.localRotation,
    63.                                        referenceGlyphTransform.localScale
    64.                                     ) :
    65.                                    Matrix4x4.TRS(
    66.                                        transform.localPosition,
    67.                                        transform.localRotation,
    68.                                        transform.localScale
    69.                                    );
    70.              
    71.                 currentVertices[TL] = matrix.MultiplyPoint3x4(sourceVertices[TL] - offset) + offset;
    72.                 currentVertices[TR] = matrix.MultiplyPoint3x4(sourceVertices[TR] - offset) + offset;
    73.                 currentVertices[BL] = matrix.MultiplyPoint3x4(sourceVertices[BL] - offset) + offset;
    74.                 currentVertices[BR] = matrix.MultiplyPoint3x4(sourceVertices[BR] - offset) + offset;
    75.             }
    76.  
    77.             m_TextComponent.UpdateVertexData(TMP_VertexDataUpdateFlags.Vertices);
    78.         }
    79.     }
    80.     IEnumerator ClearText()
    81.     {
    82.         while (true)
    83.         {
    84.             m_TextComponent.text = "A line of text.";
    85.             yield return new WaitForSeconds(1.0f);
    86.             m_TextComponent.text = string.Empty;
    87.             yield return new WaitForSeconds(1.0f);
    88.         }
    89.     }
    90. }
    I have attached the unity package with various experimental features to help you fix bugs.

    TMP.PNG

    Update : Changed image
     

    Attached Files:

  13. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    22
    umm... how's it going?
     
  14. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    1,862
    Against a deadline for Unite in LA next week and as such haven't had time to revisit this.

    As soon as I have time, I'll take a look. Thank you again for providing the package for me to look at.
     
  15. Creta_Park

    Creta_Park

    Joined:
    Mar 11, 2016
    Posts:
    22
    Thank you for listening, I hope the bugs will be fixed as soon as possible :D