Search Unity

TextMeshPro always on top of gameobjects

Discussion in 'UGUI & TextMesh Pro' started by Azgaz, Jan 26, 2022.

  1. Azgaz

    Azgaz

    Joined:
    Feb 19, 2019
    Posts:
    3
    Hey all,

    I'm having a lot of trouble getting TextMeshPro to act the way I want it to. I'm prototyping a card game and use TextMeshPro (Not UI) for the title and description. At first I was having trouble with the text rendering above the gameobject so I found that setting the shader to Distance Field Overlay fixes that, but what I'm realizing now is that it makes the text render on top of everything no matter what so when the cards overlap, you see the text of every card on top of each other.

    How can I make TextMeshPro render the text on top of the parent gameobject but also respect the Z position of the gameobject relative to the rest?

    Thanks in advance!
     
  2. Fruitfly08

    Fruitfly08

    Joined:
    Feb 5, 2021
    Posts:
    69
    I just did some testing, and if you set the canvas (that your cards and text are in) to render in world space, it'll treat the text more like a gameobject. So it'll render based off what layer it's in (so you'll be able to get the text to render the way you described in the description). So for example, let's say all your cards are on the default layer. You can set the card you want on top to have the highest priority (you can change this by changing the order in layer) and set the next card as one less priority, and so on. This should work, it did for me at least. (also, I had my cards set up as being a child object of one canvas, and the text was a child object of the individual cards, this allowed me to use only one canvas and have the text follow the cards since they're child objects. This is the set up I would recommend, oh, and also, the text will render based off the sprite renderer of the parent object, the text doesn't appear to have sorting layer settings). Let me know if you can get this to work :]
     
  3. Fruitfly08

    Fruitfly08

    Joined:
    Feb 5, 2021
    Posts:
    69
    And also, just out of curiosity, what kind of card game are you making?
     
  4. Azgaz

    Azgaz

    Joined:
    Feb 19, 2019
    Posts:
    3
    I'm not using TMP UGUI, just TMP, so the Canvas thing wasn't applicable. It turns out Distance Field Overlay was incorrect, I just wanted Distance Field and then to reposition the TMP element itself to not be inside my sprite. Otherwise, this is a Slay The Spire-type card game.
     
  5. Fruitfly08

    Fruitfly08

    Joined:
    Feb 5, 2021
    Posts:
    69
    so you got it working? :] just checking, in case you need help with anymore stuff, also, your project sounds very cool