Search Unity

Material disappears from TextMeshPro object when creating a prefab?

Discussion in 'UGUI & TextMesh Pro' started by HEATH3N, Aug 12, 2018.

  1. HEATH3N

    HEATH3N

    Joined:
    Jul 19, 2014
    Posts:
    17
    I created a TextMeshPro text object with an outline and made it into a prefab. This caused the Material component to disappear and I'm not sure if/how I can add it back. I'm using Unity 2018.1 with TextMesh Pro 1.2.4. Thanks.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The Material component not being shown on prefabs is normal behavior for Canvas related objects. When the prefab is instantiated, the material component will be added automatically.

    If you are trying to use a prefab to define a visual style (outline) for a given font asset, you should be using Material Presets to define visual styles for any given font asset. See the following video about Working with Material Presets.

    In this case, the text object from which you created this prefab would have your outline material preset assigned to it. When this object is instantiated, it would have the visual style defined by this material preset.
     
  3. HEATH3N

    HEATH3N

    Joined:
    Jul 19, 2014
    Posts:
    17
    So to create my outline style, I did the following:
    1. Create TextMesh object
    2. Right-click Material and choose "Create Material Preset"
    3. Adjust visual style
    4. Drag TextMesh object to folder to make it a prefab
    I am unsure how to link the material preset to this object. According to the video, it should appear in the Material Preset dropdown but I can only see the four default options there.

    EDIT: I got it working (I just forgot to hit Apply) but looking at the prefab object in the folder, there is no indication from where the style is coming from. If I delete the original object in the Hierarchy, I would have no idea how to change the style if necessary.
     
    Last edited: Aug 12, 2018
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    If you look at the text object inspector, it is shows what material preset is selected.

    upload_2018-8-12_14-4-41.png

    In order for your Material Presets to be listed there, they have to include the name of the font asset. So if the font asset is named "Special Font SDF", I recommend naming your preset something like "Special Font SDF - Blue Outline" where you simply append some text to describe what this Material Preset is which is this case is "Blue Outline".

    For each visual style that you want / need for any given font asset, you create a Material Preset. You then assign these to whatever text object you want to have this visual style. Be mindful these material presets may be shared by several text objects. This means that if you modify the Material Preset, you will be modifying the visual style of all text objects using it. For each unique visual style, you create a Material Preset.
     
    HEATH3N likes this.