Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Is there a way to instance the material of a submesh?

Discussion in 'UGUI & TextMesh Pro' started by awmcclain, May 20, 2019.

  1. awmcclain

    awmcclain

    Joined:
    Dec 24, 2013
    Posts:
    12
    I wrote a custom shader based on TMP's SDF shader that adds a few shader parameters that I want to control. I can successfully do this with normal TextMeshProUGUI instances.

    However, I am using a font family that has an italic face defined and the italic font asset is hooked up in the standard font asset.

    I need to control the parameters in the shader for one block of text that contains both normal and italicized text -- so one TextMeshProUGUI mesh (call that MainMesh) and one submesh (call that SubMesh) -- but I don't want those shader changes to affect other meshes that are using the same assets/materials.

    I can instance (and animate) the material on the main mesh by accessing MainMesh.FontMaterial. However, it seems like the only way to pass params to the submesh shader is to access the submesh material using SubMesh.SharedMaterial or MainMesh.FontSharedMaterials -- but that doesn't instance the material, so when I make changes to the italic submesh, it affects all the other italicized meshes in the scene (since we're altering the shared material). If I try and call Material.SetFloat() using SubMesh.Material or MainMesh.FontMaterials, the submesh material doesn't update.

    I _think_ that there is some magic going on with the main mesh which is assigning or reassigning the material on the submesh (which makes sense, since it's creating the submesh based on the <i> tag in the main mesh).

    Any ideas? Thank you so much!
     
  2. wechat_os_Qy03ZcfHtYNbeFalceZtkH0Oc

    wechat_os_Qy03ZcfHtYNbeFalceZtkH0Oc

    Joined:
    May 12, 2022
    Posts:
    8
    I am having a similar issue, need to control the material of submesh independent of the main mesh material. Wonder if you have found a solution. Trying to parse their code to find that "magic" but no luck so far.