Search Unity

Resolved Wired shapes shown when i change outline size of textmeshpro from script

Discussion in 'Scripting' started by naoufelbougueroua, Nov 18, 2022.

  1. naoufelbougueroua

    naoufelbougueroua

    Joined:
    May 29, 2021
    Posts:
    7
    i built i custom editor that allows me to change many gameobject text settings like changing the font color and adding outline and more

    when i set the stroke size = 0 , everything works fun with every font i try but when i change the stoke size only default unity font works other fonts shows a weird shapes like this :

    i tried changing the stroke(outline) individually from inspector and its works well so maybe i miss something on the script
    this is the script
    Code (CSharp):
    1. public void UpdateSettings()
    2. {
    3.     for(int x=0;x<transform.childCount ;x++)
    4.         {
    5.             GameObject country = transform.GetChild(x).gameObject;
    6.             country.GetComponent<SpriteRenderer>().color = countriesColor;
    7.             country.transform.GetChild(0).gameObject.SetActive(showNames);
    8.             if(showNames)
    9.             {
    10.             TextMeshProUGUI text = country.transform.GetChild(0).GetComponent<TextMeshProUGUI>();
    11.             Material mat = text.fontSharedMaterial;
    12.             if(fontAsset != null)
    13.             {
    14.             text.font = fontAsset;
    15.             }
    16.             if(strokeSize == 0)
    17.             {
    18.              
    19.             }
    20.             else
    21.             {
    22.                 mat.shaderKeywords = new string[]{"OUTLINE_ON"};
    23.             }
    24.             text.color = fontColor;
    25.             text.fontStyle = fontStyle;
    26.             text.outlineWidth = strokeSize;
    27.             text.outlineColor = strokeColor;
    28.             text.text = country.name;
    29.             }
    30.         }
    31.      
    32. }
    note : i am using unity 2019.4
     
    Last edited: Nov 18, 2022
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    This doesn't relate to any 2D feature. I'll move your post to the Scripting forum.

    Please note, you can post code using code-tags, you don't need to paste screenshots which make it very hard for someone to refer to the code. They cannot copy/paste, refer to a line number etc.

    Also note, you can edit your posts. :)
     
  3. naoufelbougueroua

    naoufelbougueroua

    Joined:
    May 29, 2021
    Posts:
    7
    sorry i was hurry i updated the thread
     
  4. naoufelbougueroua

    naoufelbougueroua

    Joined:
    May 29, 2021
    Posts:
    7
    i fixed the problem by unpacking the prefab completely i don't know why but its worked