Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question TMP characters disappear when screen size is changed in Google Chrome

Discussion in 'Web' started by unitsume, Aug 16, 2023.

  1. unitsume

    unitsume

    Joined:
    Oct 7, 2022
    Posts:
    31
    Hello.
    I'm creating a WebGL built application.
    If you display it in Google Chrome and change the screen size, the characters of TMP will disappear.
    This phenomenon does not occur in FireFox.
    How should I deal with this phenomenon?

    If you don't have enough information to answer, please contact us.
    thank you.
     
  2. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    60
    This is also happening to us, we are using 2022.3.5f1 and TextMeshPro 3.0.6
    In our testing we see difference in behaviour in our main menu and ingame, the problem doesn't seem to happen in the main menu, but I have no clue what could be the difference that triggers the issue ingame.

    Thanks for any information
     
  3. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,256
    Did you set your canvas to resize?
     
  4. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    60
    This is the config that I have in the canvas

    upload_2023-8-17_16-19-30.png

    and ingame we also have a temporal scaling that allowed us to resize all of our ingame ui (we wanted everything a % smaller without big prefab changes, and allowing us to adjust that per platform)

    Code (CSharp):
    1. public class CanvasGlobalScaler : MonoBehaviour
    2.     {
    3.         public List<CanvasScaler> canvasScalers;
    4.         public void Awake()
    5.         {
    6.             var factor = GlobalData.Instance.mainConfig.uiScaleFactor;
    7.             foreach (var canvasScaler in canvasScalers)
    8.             {
    9.                 var a = canvasScaler.referenceResolution;
    10.                 canvasScaler.referenceResolution = (double)Mathf.Round(canvasScaler.matchWidthOrHeight) != 0.0 ? Vector2.Scale(a, new Vector2(1f, factor)) : Vector2.Scale(a, new Vector2(factor, 1f));
    11.             }
    12.             Canvas.ForceUpdateCanvases();
    13.         }
    14.     }
    everything else in those canvases looks perfect, only the textmeshpro labels dissapear
     
  5. bugfinders

    bugfinders

    Joined:
    Jul 5, 2018
    Posts:
    2,256
    hm, mine are OK as long as I set the anchors OK.. if I mess that up they go walk about but otherwise never had issues..
     
  6. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    60
    Do you have any more information with this? I am trying to replicate it in a separate project, but there it works just fine.
    I can't imagine what is different here.

    Another weird thing that I tried is using https://github.com/yasirkula/UnityRuntimeInspector to setup a way to check if anything was obviously wrong, and when I try to inspect the TMP component that became invisible, it reappears, but if I change anything it dissapears again.

     
  7. rubeng

    rubeng

    Joined:
    Apr 20, 2013
    Posts:
    60
    I crossposted the thread in the tmp/ugui forum, to see if anyone there has an idea.
     
  8. JolanHuyvaertDieKeure

    JolanHuyvaertDieKeure

    Joined:
    Mar 1, 2021
    Posts:
    9
    We also have TMP text disappearing in WebGL builds when going to full screen. It only happens in Chromium based browsers (Chrome & Edge) on Windows (tested on Windows 10). Chrome on Android, Chromebook and on iOS are fine.
    We use Unity 2022.3.0 at the moment, but we had this happening in the previous LTS (2021.3) as well. My colleague did an extensive effort to try to repro the issue and find possible fixes/workarounds. I will ask him to share his findings here as well.
     
    MargotDeSaegher, rubeng and jhuyvaert like this.
  9. Arne_VdB

    Arne_VdB

    Joined:
    Oct 7, 2019
    Posts:
    1
    Temporary fix I have discovered:

    => Duplicate the affected font
    => Activate "Underlay" in the material and put alpha to 1.0 (or 0.0 seems to work as well)
    => Within the affected TMPro component, assign this newly created font.

    This is no guarantee the bug is gone forever, it is possible the font gets "infected" again,
    but at least there is text in specific builds.

    I have tested this on two different occasions now and this seems to work consistently.
     
    grit and MargotDeSaegher like this.
  10. 30035172

    30035172

    Joined:
    Jun 25, 2016
    Posts:
    17
    I made a tool to fix, worked for me

    first duplicate your textmeshpro font and call it 3D (use the 3D font for world space canvas, or no canvas)
    then create 'Assets\Editor\FindTextMeshProEditor.cs'
    then go tools > find textmeshpro in scene
    then replace the fonts

    View attachment 1393426




    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using TMPro;
    4. using System.Collections.Generic;
    5. using System.Linq;
    6.  
    7. public class FindTextMeshProEditor : EditorWindow
    8. {
    9.     private Vector2 scrollPosition;
    10.     private Dictionary<string, List<GameObject>> foundObjectsGrouped = new Dictionary<string, List<GameObject>>();
    11.     private TMP_FontAsset selectedFont;
    12.     private Material selectedMaterial;
    13.  
    14.     [MenuItem("Tools/Find TextMeshPro in Scene")]
    15.     public static void ShowWindow()
    16.     {
    17.         GetWindow<FindTextMeshProEditor>("Find TextMeshPro");
    18.     }
    19.  
    20.     void OnGUI()
    21.     {
    22.         if (GUILayout.Button("Find All TextMeshPro Components"))
    23.         {
    24.             FindAllTextMeshProComponents();
    25.         }
    26.  
    27.         if (GUILayout.Button("Clear Results"))
    28.         {
    29.             ClearResults();
    30.         }
    31.  
    32.         GUILayout.Label("Found Objects:", EditorStyles.boldLabel);
    33.         scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true);
    34.         foreach (var pair in foundObjectsGrouped)
    35.         {
    36.             GUILayout.Label(pair.Key, EditorStyles.boldLabel);
    37.             foreach (GameObject obj in pair.Value)
    38.             {
    39.                 EditorGUILayout.ObjectField("Object:", obj, typeof(GameObject), true);
    40.             }
    41.  
    42.             if (pair.Value.Count > 0)
    43.             {
    44.                 EditorGUI.indentLevel++;
    45.                 DrawFontAndMaterialSelectors(pair.Key, pair.Value);
    46.                 EditorGUI.indentLevel--;
    47.             }
    48.         }
    49.         GUILayout.EndScrollView();
    50.     }
    51.  
    52.     private void DrawFontAndMaterialSelectors(string key, List<GameObject> objects)
    53.     {
    54.         EditorGUILayout.BeginHorizontal();
    55.         GUILayout.Label("Change Font Asset:", GUILayout.Width(150));
    56.         selectedFont = EditorGUILayout.ObjectField(selectedFont, typeof(TMP_FontAsset), false) as TMP_FontAsset;
    57.         EditorGUILayout.EndHorizontal();
    58.  
    59.         EditorGUILayout.BeginHorizontal();
    60.         GUILayout.Label("Change Material:", GUILayout.Width(150));
    61.         selectedMaterial = EditorGUILayout.ObjectField(selectedMaterial, typeof(Material), false) as Material;
    62.         EditorGUILayout.EndHorizontal();
    63.  
    64.         if (GUILayout.Button("Apply Changes"))
    65.         {
    66.             ApplyFontAndMaterialChanges(objects);
    67.         }
    68.     }
    69.  
    70.     private void ApplyFontAndMaterialChanges(List<GameObject> objects)
    71.     {
    72.         Undo.RecordObjects(objects.ToArray(), "Change TMP Font/Material"); // Prepare for undo
    73.  
    74.         foreach (GameObject obj in objects)
    75.         {
    76.             // Apply changes to TextMeshProUGUI components (UI TextMeshPro)
    77.             var textComponentsUI = obj.GetComponentsInChildren<TextMeshProUGUI>(true);
    78.             foreach (var textComp in textComponentsUI)
    79.             {
    80.                 if (selectedFont != null)
    81.                 {
    82.                     Undo.RecordObject(textComp, "Change TMP Font");
    83.                     textComp.font = selectedFont;
    84.                     EditorUtility.SetDirty(textComp); // Mark the component as dirty
    85.                 }
    86.  
    87.                 if (selectedMaterial != null)
    88.                 {
    89.                     Undo.RecordObject(textComp, "Change TMP Material");
    90.                     textComp.fontSharedMaterial = selectedMaterial;
    91.                     EditorUtility.SetDirty(textComp); // Mark the component as dirty
    92.                 }
    93.             }
    94.  
    95.             // Apply changes to TextMeshPro components (3D TextMeshPro)
    96.             var textComponents3D = obj.GetComponentsInChildren<TextMeshPro>(true);
    97.             foreach (var textComp in textComponents3D)
    98.             {
    99.                 if (selectedFont != null)
    100.                 {
    101.                     Undo.RecordObject(textComp, "Change TMP Font");
    102.                     textComp.font = selectedFont;
    103.                     EditorUtility.SetDirty(textComp); // Mark the component as dirty
    104.                 }
    105.  
    106.                 if (selectedMaterial != null)
    107.                 {
    108.                     Undo.RecordObject(textComp, "Change TMP Material");
    109.                     textComp.fontSharedMaterial = selectedMaterial;
    110.                     EditorUtility.SetDirty(textComp); // Mark the component as dirty
    111.                 }
    112.             }
    113.         }
    114.     }
    115.  
    116.  
    117.     private void FindAllTextMeshProComponents()
    118.     {
    119.         foundObjectsGrouped.Clear(); // Clear the results before searching
    120.  
    121.         var allTextMeshObjects = FindObjectsOfType<TextMeshPro>().Cast<Component>()
    122.             .Concat(FindObjectsOfType<TextMeshProUGUI>())
    123.             .Select(component => component.gameObject).Distinct();
    124.  
    125.         foreach (var obj in allTextMeshObjects)
    126.         {
    127.             Canvas parentCanvas = obj.GetComponentInParent<Canvas>();
    128.             string key = parentCanvas != null ? $"Canvas: {parentCanvas.name}" : "No Canvas";
    129.  
    130.             if (!foundObjectsGrouped.ContainsKey(key))
    131.             {
    132.                 foundObjectsGrouped[key] = new List<GameObject>();
    133.             }
    134.             foundObjectsGrouped[key].Add(obj);
    135.         }
    136.  
    137.         if (foundObjectsGrouped.Count == 0)
    138.         {
    139.             Debug.Log("No TextMeshPro components found in the scene.");
    140.         }
    141.     }
    142.  
    143.     private void ClearResults()
    144.     {
    145.         foundObjectsGrouped.Clear();
    146.     }
    147. }
    148.