Search Unity

Bug My text in canvas disappear when resizing

Discussion in 'Editor & General Support' started by mrobiwankenobi, Jan 27, 2023.

  1. mrobiwankenobi

    mrobiwankenobi

    Joined:
    Aug 7, 2021
    Posts:
    5
    Hello, hope you're all doing well. Need an assistance if someone could help with this issue that might be just a little thing but which is strange.
    i'm a beginner so please talk me like a full newbie here :)

    As you can see on screenshot 1 I have a canvas menu that works perfectly in the editor and on build on my laptop (Macbook pro).




    When I open the build on my Desktop Mac, it works. Until I resize the window then my canvas automatically become white like in screenshot 2. It is strange that this not occurs on my laptop. And when I get restart the build, then the menu show again with the same resizing I made, if I change again the size of the window, blank again. I might think it's not like it disappears but their is something masking it, don't know. Again this not occur on my laptop which drive me crazy.




    Don't know from where come the issue I put some screenshots about my config... I tried several setups even in my player setting (in text mesh pro like resizing text and so) but still got the issue. Thank you if anyone could conduct me in some logic thoughts here.

    Canvas where it occurs setting:



    The menu panel and buttons settings:




     
    Last edited: Jan 27, 2023
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Check the horizontal / vertical overflow settings on the text object itself.

    If they are set to Truncate then they might blank the text unexpectedly, as the actual text "squares" are almost always larger vertically than the actual letter itself.

    Otherwise, check your anchoring and scaling:

    Here are some notes on UI Anchoring, Scaling, CanvasScaler, etc:

    https://forum.unity.com/threads/inc...size-between-two-people.1130146/#post-7261747

    https://forum.unity.com/threads/game-ui-button-size-problem.1142650/#post-7337383
     
  3. mrobiwankenobi

    mrobiwankenobi

    Joined:
    Aug 7, 2021
    Posts:
    5
    Thank you for your feedback Kurt.
    Here are my settings it was not Truncate.
    I literally tried all the options from there, selecting, deselecting (to also learn the effects of them) got the same issue each time on the build from my Desktop.
    Any other suggestion here? Might it come from somewhere else in the project?


     
  4. mrobiwankenobi

    mrobiwankenobi

    Joined:
    Aug 7, 2021
    Posts:
    5
    Found out from where came the bug. From the material of text mesh pro, had to turn it from distance field to distance field overlay. Too much options/parameters for a simple text ;). Will check if this doesn't create unsuspected bugs in my menu later. Hope this can helps some once.

    Ps: thank you again Kurt. You're great to help so much people with your experience

     
    Last edited: Jan 30, 2023
    BamBooEd and VisualDima like this.
  5. mitesh_unity199

    mitesh_unity199

    Joined:
    Dec 19, 2021
    Posts:
    2
    You just save my day, this solution worked for us too.
     
  6. VisualDima

    VisualDima

    Joined:
    May 21, 2020
    Posts:
    19
    Thank you, mrobiwankenobi!
     
  7. BamBooEd

    BamBooEd

    Joined:
    Aug 23, 2017
    Posts:
    1
    Just a Magic. Thank You))
     
  8. 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

    upload_2024-3-31_4-36-2.png

    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.