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. Dismiss Notice

How to mask TextMesh renderers

Discussion in 'Editor & General Support' started by BCook99, Jul 8, 2020.

  1. BCook99

    BCook99

    Joined:
    Feb 17, 2015
    Posts:
    11
    Our game has a number of sprites using SpriteRenderer that are masked with a SpriteMask. The sprites are organized with sorting groups and sort order, etc. This works well.

    Now we need to attach a dynamic text display to some sprites. We can do this using TextMesh or the Text Mesh Pro text mesh, or even attaching a small Canvas in world space and using a Text UI component. All of these draw the text fine but none of them will respect the SpriteMask. How can we mask the text without a radical re-vamp of our game? Can this be done using a custom shader and if so, how?
     
  2. HajiyevEl

    HajiyevEl

    Joined:
    Feb 19, 2020
    Posts:
    41
    Last edited: Aug 2, 2020
  3. cathode26

    cathode26

    Joined:
    Jul 21, 2011
    Posts:
    27
    Bump, I have this same problem. I am using MeshRenderer with TextMeshPro Text. I am not using a canvas, has anyone figured out how to mask this text?
     
  4. BCook99

    BCook99

    Joined:
    Feb 17, 2015
    Posts:
    11
    I managed to get this working pretty well by writing a custom script that takes a Text, TextMesh, or TMP_Text and renders it into a Texture2D using a dedicated text rendering camera. Then I create a sprite from the texture and assign it to a SpriteRenderer and disable the original Text/TextMesh/TMP_Text.