Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Animating Vertex Attributes of Text in Layout Group

Discussion in 'UGUI & TextMesh Pro' started by smonbrogg, Aug 31, 2023.

  1. smonbrogg


    Dec 11, 2012
    Where should I put the code that animates vertex attributes of a TextMeshProUGUI component if this is also animated with parent layout components?

    I would like to update the text animation after the canvas is rebuild.

    Changing text values is not a problem, the text is constant in my case.

    I am instantiating the TextMeshProUGUI and positioning it with Canvas layout elements.

    Currently (using coroutings like in the example) the animation works, but the text is first shown without animation for a frame before the animation starts. This is not nice since the animation is supposed to let the text appear.
  2. smonbrogg


    Dec 11, 2012
    I think I'm starting to understand...

    The VertexJitter.cs in Animating Vertex Attributes sample seems to recalculate the bounds of the text. When animating text that is supposed to fly into its place in the UGUI Layout, this is not desired because the UIGUI Layout rebuilder might rearrange according to the new text bounds. So now I am trying to "Push changes into meshes" without recalculating the bounds. Currently I'm doing this with canvasRenderer.SetMesh, but only with the first mesh. I'm ignoring subTextObjects.

    Code (CSharp):
    2.                 // VertexJitter.cs line 162
    3.                 // Push changes into meshes
    4.                 for (int i = 0; i < textInfo.meshInfo.Length; i++)
    5.                 {
    6.                     textInfo.meshInfo[i].mesh.vertices = textInfo.meshInfo[i].vertices;
    8.                     // This recalculates the bounds. I dont want that because it messes up my UGUI layout.
    9.                     //m_TextComponent.UpdateGeometry(textInfo.meshInfo[i].mesh, i);
    11.                     // update geometry without recalculating bounds
    12.                     if (i == 0)
    13.                     {
    14.                         m_TextComponent.canvasRenderer.SetMesh(textInfo.meshInfo[i].mesh);
    15.                     }
    16.                     else
    17.                     {
    18.                         // how do I find the canvas renderer of the sub text objects?
    19.                         // what are sub text objects anyway???
    20.                         //m_subTextObjects[i].canvasRenderer.SetMesh(textInfo.meshInfo[i].mesh);
    21.                     }
    22.                 }

    Hopefully this will work for me. If anyone has a better / cleaner way, or more insight, I'd be happy to hear!
    Last edited: Sep 1, 2023
  3. smonbrogg


    Dec 11, 2012
    It doesn't. I cant seem to animate tmPro text into its place in the UGUI Layuot :-(