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 Creating a TMPro UI material from a TMPro Surface material?

Discussion in 'UGUI & TextMesh Pro' started by Yandalf, Mar 17, 2022.

  1. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    Hey!

    Is there a (convenient) way to create a new material for a TMP UI element, using a TMP Surface element's material as a base? I've tried creating a new material with a (hard-coded) reference to the desired UI shader, then using Material.CopyPropertiesFromMaterial, but this mostly resulted in a ton of errors in the log about certain properties not existing in either material.
    Does manually copying over the right properties even work? Or is that actually not the way to go with TMP Materials and presets?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The easiest way to create new material presets in the Editor is to simply use the context menu created for that purpose as seen below.

    upload_2022-3-17_14-22-57.png

    The process is pretty simple.

    1. Select the text object.
    2. Right click on the material inspector to bring up the context menu.
    3. Select Create Material Preset.
    4. New material will be created and automatically assigned to the text object. It will also be pinged in the project tab so you can rename it if desired.

    The following video (although old now) covers this process although the context menu option was renamed in subsequent releases.

     
    EDevJogos likes this.
  3. Yandalf

    Yandalf

    Joined:
    Feb 11, 2014
    Posts:
    491
    I know about this, but I'm looking at creating these new materials at runtime through code.
    I used a workaround instead, turns out the standard TMP Materials work well enough both in UI as well as in world elements, making a "material conversion" unnecessary.

    Side question, is it intentional that Surface TMP shaders aren't supported in URP? All other shaders seem to work fine, but Surface TMP materials result in lovely magenta squares.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Surface shaders are not compatible with SRP. This is not specific to TMP but to all Surface Shaders.

    The latest release of TMP includes new SRP shaders. These include Unlit and Lit URP and HDRP shaders.

    The latest release is version 3.2.0-pre.3 available for Unity 2020.3 or newer.