Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

TextMesh Pro TextMeshProUGUI Outline Masking

Discussion in 'UGUI & TextMesh Pro' started by corrivai, Oct 4, 2018.

  1. corrivai

    corrivai

    Joined:
    Mar 14, 2016
    Posts:
    12
    Hi, i have a simple scene with 3 components: Canvas, image (with mask script) and a textmeshproUgui omponent.


    (https://ibb.co/ngZrRz)
    I can't change the outline color with this configuration.


    (https://ibb.co/drTJ6z)

    This is the SampleText script:

    Code (CSharp):
    1. public TMP_FontAsset font;
    2.     public Material outlineMateria;
    3.     TextMeshProUGUI txtP;
    4.  
    5.     public void Start()
    6.     {
    7.         txtP = gameObject.AddComponent<TextMeshProUGUI>();
    8.         txtP.text = "Prova";
    9.  
    10.         txtP.font = font;
    11.         txtP.fontSharedMaterial = new Material(outlineMateria);
    12.     }
    13.  
    14.     float m_frame = 0;
    15.     public void Update()
    16.     {
    17.         m_frame += 1 * Time.deltaTime;
    18.         Color c = new Color32((byte)((m_frame * 100) % 255), (byte)((m_frame * 100) % 255), (byte)(m_frame % 255), 255);
    19.  
    20.         txtP.outlineColor = c;
    21.        
    22.         //txtP.fontSharedMaterial.SetColor("_OutlineColor", c);
    23.     }
    If the mask component is disabled, the outline color changes, but I need the mask…

    Can you help me?
    Thank you
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Most likely the issue is the result of both the UI.Mask creating an instance material with the masking setting and then the .outlineColor which also creates an instance material.

    Since the outlineColor is really a material property, change the material property on the fontSharedMaterial. See the following post.
     
  3. corrivai

    corrivai

    Joined:
    Mar 14, 2016
    Posts:
    12
    Ok, i changed my script, but the color does not change..

    Code (CSharp):
    1. public void Update()
    2.     {
    3.         m_frame += 1 * Time.deltaTime;
    4.         Color c = new Color32((byte)((m_frame * 100) % 255), (byte)((m_frame * 100) % 255), (byte)(m_frame % 255), 255);
    5.  
    6.         //txtP.outlineColor = c;
    7.  
    8.         txtP.fontSharedMaterial.SetColor(ShaderUtilities.ID_OutlineColor, c);
    9.         //txtP.UpdateMeshPadding();
    10.     }
    I tried with the Rect Mask 2D component and the color now changes, but the text overlaps the image... 43104935_333153053911737_3493537294898429952_o.jpg

    :(
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Since the UI.Mask ends up creating a material instance of its own, it is likely that you are modifying the color of the material used to create the instance and not the instance itself. That should be easy to check via the name of the material you are modifying. If its name includes some ID then it is the mask material otherwise it is not.

    See if the fontMaterial is the instance again by checking its name. If it is the mask material, then you should be able to modify it as above. Given it is already an instance, it should no longer get instanced.
     
  5. corrivai

    corrivai

    Joined:
    Mar 14, 2016
    Posts:
    12
    Ok, I tried to change the color of the material without creating a new instance.
    But I don't solve the problem. This is my situation:

    iuopui.PNG
    I set the outlineMaterial from the editor.

    When i run the application, the material in txtP.fontSharedMaterial is a new instance. How can I avoid it?