Search Unity

Bug TMPro rendering issue caused by parent scale animation

Discussion in 'UGUI & TextMesh Pro' started by Kazeon, Sep 26, 2020.

  1. Kazeon

    Kazeon

    Joined:
    May 22, 2017
    Posts:
    41
    Bug reproduction steps:
    1. Create an empty object (UI) as parent
    2. Create some text mesh pro UGUI as childs of that object
    3. Add an animation to the parent object which animates it's scaling (x, y, & z), like shrinking/expanding animation
    4. Close/hide the "Scene" tab (important) then play the game & animation

    Result:
    All the child tmp objects will be rendered as blocks
    upload_2020-9-26_21-25-58.png

    Reproduction rate: 100%

    Unity version: 2019.2.6f1
    TextMeshPro version: 2.0.1

    Side Note:

    - The objects will be rendered normally only if the scene tab is open/active, which means it won't get fixed on production (build)
    - The objects will be refreshed properly when changing resolution or any property of each TMpro objects
     
    Last edited: Sep 26, 2020
  2. Kazeon

    Kazeon

    Joined:
    May 22, 2017
    Posts:
    41
    The forum doesn't allow me to edit my main post so here is my temporary fix for the issue:

    Create a script for the parent object that will populate all children TMP objects, and then call ForceMeshUpdate on each child on every frame Update, only when the parent animation is playing.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using TMPro;
    5.  
    6. public class ForceUpdateTMP : MonoBehaviour
    7. {
    8.     public List<TextMeshProUGUI> texts;
    9.  
    10.     // Start is called before the first frame update
    11.     void Start()
    12.     {
    13.         texts.AddRange(GetComponentsInChildren<TextMeshProUGUI>(true));
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.         for (int i = 0; i < texts.Count; i++)
    20.             texts[i].ForceMeshUpdate();
    21.     }
    22. }
    23.  
    I do hope there's more elegant and efficient solution to this, and the bug fix.