Search Unity

TMPro example 23 not coloring first character

Discussion in 'UGUI & TextMesh Pro' started by Lednar, Oct 2, 2018.

  1. Lednar

    Lednar

    Joined:
    Jan 9, 2018
    Posts:
    14
    I am playing around with example 23 - Animating Vertex Attributes and then I remove VertexJitter script from the text object, so only running coloring script on the text object. I have noticed that the first characters is not colored on first cycle. What can be the problem, is it a bug in Unity or in TMPro plugin?

    PS! I am using Unity 2017.4.3 and tmpro is from asset store.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The reason why the first character doesn't change color is simply due to the fact that when the coroutine is called in Start(), the text object and its geometry hasn't been generated yet which happens in OnPreCull.

    There are different ways this could be handled.

    The first could be to delay the coroutine by adding the following at line 31. The would result in the text object being updated on the first frame and then subsequently get its colors modified.

    Code (csharp):
    1.  
    2. yield return new WaitForEndOfFrame();
    3.  
    You could also force the text object to update right away. To do this you would add the following instead at line 31.

    Code (csharp):
    1.  
    2. m_TextComponent.ForceMeshUpdate();
    3.  
    I have made several posts about the purpose of the ForceMeshUpdate() function. A search on this will reveal additional information.
     
    Lednar likes this.