Search Unity

TextMesh Pro Enabling outline with script

Discussion in 'UGUI & TextMesh Pro' started by io3creations, May 5, 2018.

  1. io3creations

    io3creations

    Joined:
    May 18, 2015
    Posts:
    11
    This is a Texmesh Pro noob question and might be more of a confirmation check.

    I've added a Textmesh Pro component to a GameObject in script. (The same type that is added with: GameObject->3D Object->TextMeshPro Text)
    Then, I modified certain properties (still in script). Most changes did show up but the outline didn't. More specifically, I was able to set the outline color and thickness, but the "Enable -> []" checkbox to the right of "Outline -Settings-" was still unchecked.
    As I tried a few things, it seems like that checkbox setting is related to the font material.

    So, similarly to "regular" materials, if I create a first in the Unity Editor with the desired settings (e.g. enable outline) then the scripts can change the other properties, right?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    On my cell phone so short reply.

    The outline uses a shader keyword and as such it has to be enabled on the material.

    See the following thread.
     
  3. io3creations

    io3creations

    Joined:
    May 18, 2015
    Posts:
    11
    Thanks for the reply.

    In that case, for now it seems like that it is easier to create and set up different font materials in the Editor and just change certain properties (e.g. font size) as needed. But later on there probably will be situations where I will cases that require turning on and off certain shader keyword based features.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Unless you need to dynamically change the visual appearance of the material (which can be even done with the Animation component in Unity), it is best to use Material Presets. See the following video about Material Presets.

    The intro of this video shows a good example of animating material properties using the Animation component in Unity.
     
  5. Rickmc3280

    Rickmc3280

    Joined:
    Jun 28, 2014
    Posts:
    189
    The link above is not available anymore as of 12/14/2021. Having a similar issue. Have stumbled on this thread 3x now so wanted to update.
     
  6. evansmalley2

    evansmalley2

    Joined:
    Apr 15, 2018
    Posts:
    1
    same here...documentation for textmeshpro is complete trash
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    There are a few threads on the forum about this topic. Having said that the procedure is as follows:

    First keep in mind that the outline is just a material property where as such, any of the material properties can be changed via the material API and as per this example. In this case, the Face Dilation is being changed but the process is identical for changing any other material properties.

    Here is a link to the ShaderUtilities class which contains all the material IDs.

    The next piece that is important to keep in mind is that some of the material properties are controlled by shader keywords which must be enabled which can also be done via code. The following post contains code snippets also related to this.