Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question 2d urp, world space TextMeshPro not rendering on top with Z-value to 0

Discussion in 'UGUI & TextMesh Pro' started by Unideer, Feb 21, 2024.

  1. Unideer

    Unideer

    Joined:
    Feb 24, 2023
    Posts:
    21
    The text is a free floating damage popup. Its Z-value is set to 1. It's not rendering on top:

    321-02-21 095022.jpg


    I think it's to do with 2d sorting layers? But there is no option in the textmeshpro or mesh renderer component to adjust 2d sorting layers
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,474
    Check your canvas
    upload_2024-2-21_8-27-24.png

    Also, if the other object that is blocking is on the same canvas, change their child order in the scene hierarchy. That will determine the render order as well
     
  3. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,520
    Is this using or not using a canvas?

    If off canvas, then SortingOrder may be relevant. The sortingOrder property is hidden in the Inspector for TextMeshPro. But you can see it if you flip into Inspector's Debug mode (right click on the Insepctor tab then go to Debug).

    Or you can set it by script
    myTextMeshPro.sortingOrder = 123;
     
    Last edited: Feb 21, 2024
  4. Unideer

    Unideer

    Joined:
    Feb 24, 2023
    Posts:
    21
    It's off canvas. Changing sorting order won't work. But I managed to
    msrenderer.sortingLayerName = "UI";

    So is there a way i can force this number in debug inspector or something?

    Or am I implementing damage popups incorrectly that i should just use canvas?
     
  5. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,474
    There is no right way, it just depends on what you are going for. But if you are making a 2D game, then UI makes a lot of sense since everything is "flat". Text is generally a UI element, unless you are using 3D text. So if you are making text popups showing numbers, UI is a nice and neat solution. And easy to manipulate what is in front/back/behind of each other.

    Here is a brief explanation of the draw order: LineRenderer sorting order / layer problem - Can LineRenderers be layered in between UI elements? - Unity Forum

    Here are a couple videos that i used way back when on implementing damage popups: upload_2024-2-23_8-0-57.png

    It is a nice, simple way of doing it.
     
    Unideer likes this.