Search Unity

Question How to programmatically change the Material used in a Text Mesh Pro component to a Material Preset

Discussion in 'UGUI & TextMesh Pro' started by literacy, Apr 13, 2023.

  1. literacy

    literacy

    Joined:
    Nov 14, 2021
    Posts:
    56
    I added a Text Mesh Pro component to a GameObject, and applied a font, KGRHMain.

    jRQYK.png

    I would like to programatically change the Material used in the Mesh Renderer, from the default material to KGRHMain Shadows.

    hFzxX.png

    When I do this manually, I get exactly the result that I want. But when I try doing this programatically, the Material used in the Mesh Renderer doesn't change.
    HsG9g.png I've tried many variations, but can't get it to work. I think I'm lacking some conceptual understanding of how to change Materials using Material Presets.

    How can I change the Material in the Mesh Renderer to use the Material Preset that I want? (KGRHMain Shadows)
     
  2. literacy

    literacy

    Joined:
    Nov 14, 2021
    Posts:
    56
    Ah ok, I see now... I can ignore the Mesh Renderer component and just use the Text Mesh Pro component.