Search Unity

TextMesh Pro How to render TextMeshPro the last regardless of Hierarchy?

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by 5argon, Sep 15, 2018.

  1. 5argon


    Jun 10, 2013
    You know uGUI relies a lot on hierarchy ordering. And each TextMeshPro text will probably have its own SDF material so it cannot be batched. The ideal for non-occluded TextMeshPro is to have them drawn the last after everything else.

    In this picture, the 873 and 1000000 number was from the same SDF TextMeshPro material (with the "Overlay" variant so they would draw the last) But when using Frame Debugger, it is still being drawn sequentially from top of hierarchy to the bottom, resulting in batch breaking even though nothing will be displayed over them.

    Screenshot 2018-09-15 17.01.45.png

    Here, the hierarchy tree would look like this because I wanted them to animate together. Everything are under the same Canvas :

    Code (CSharp):
    2. >Judgement
    3. >>RedPerfect
    4. >>>873
    5. >>Perfect
    6. >>>873
    7. >>Good
    8. >>>873
    9. >>Miss
    10. >>>873
    11. >Score
    12. >>1000000
    My current solution is to "peel" them out to a separated canvas (Inherit settings, but with overridded sorting to be the old one +1) positioned at the bottom, collecting them. This way they would be drawn last like before, but the batch not breaking. Because a new canvas will guarantee separated batch.

    Code (CSharp):
    2. >Judgement
    3. >>RedPerfect
    4. >>Perfect
    5. >>Good
    6. >>Miss
    7. >>InnerCanvas
    8. >>>873
    9. >>>873
    10. >>>873
    11. >>>873
    12. >Score
    13. >>1000000
    But it is a hassle because I have to do this after the animation and restore them when I want to do animation again so they go together with their parents.

    Can you make the "Distance Field Overlay" material drawn last regardless of where it is on the hierarchy? (Preferrably sorted by material types after they are all grouped the last) Or any better way? Thank you.