Search Unity

TextMesh child behind parent

Discussion in '2D' started by Screeze, Nov 19, 2018.

  1. Screeze

    Screeze

    Joined:
    Nov 16, 2018
    Posts:
    5
    Hi,

    I have following structure:

    Scene
    - Main Camera
    - Sprite 1 (Sorting Layer: Default, Order 1)
    - Sprite 2 (Sorting Layer: Default, Order 4)
    -- TextMesh (could not find sorting layer or order property)

    The sprites are simple squares on top of each other (2 on top of 1). The text mesh is a game object child with text mesh on it on Sprite 2. Now I have following issue:
    My Text is displayed behind all other sprites (1 and 2!). I only can see it if I change the color of Sprite 1 and Sprite 2 to transparent (no the color is not identical ;) ).

    Why is this the case?
    From what I found the child should always render on its parent. I tried around with different Z offsets or similar, but nothing changed.

    I started using Unity 2 days ago so sorry if this is a noob question ;)

    Greetings
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    this is working for objects in canvas.

    sprites are using order in layer (or z-position with other objects). Look ate the canvas from the textmesh, there should be "Order in Layer" field(if you are using World Space). Put in in greater value as by the other sprites.
     
  3. Screeze

    Screeze

    Joined:
    Nov 16, 2018
    Posts:
    5
    Thanks for your response.
    What do you mean by "if you are using World space"?

    I only have Pos Z (in Rect Transform) and Offset Z (in Text Mesh). Both have no effect. I have "Order in Layer" in the parent object but not in the text mesh child.
     
  4. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    sorry, I have thought, you are using textmeshpro with canvas. Did you trid to make offset z negative (- 5 as example or more) ?
     
  5. Screeze

    Screeze

    Joined:
    Nov 16, 2018
    Posts:
    5
    Yes I did, even with -500 (also tried +500) nothing changes :(
    Any other ideas?

    Adding another sprite as children to the sprite which also contains the text works as expected when setting the order in Layer value of the inner child accordingly. But I don't have this value in the textmesh :/

    wondering if this has to do with https://answers.unity.com/questions/928346/basic-text-sub-component-of-sprite-prefab-not-show.html but I don't understand how I could fix this

    Here is some overview of what I mean:
    unity-text.PNG
     
    Last edited: Nov 24, 2018
  6. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    what is this white box ? What is inside of the canvas ?

    If the white box just should be the background then make it as simple sprite object (with negative position and order in layer) and not inside the canvas.

    UI-Objects in the overlay canvas are always on the top independet from other values. Inside this canvas the ui-objects are sorted depended on their child position.
    Sprites are sorted based on their order in layer (or z-position if orders in layer are equal).
    3d objects depended on their z-position.
    3d objects and sprites - again z-position.
     
  7. Screeze

    Screeze

    Joined:
    Nov 16, 2018
    Posts:
    5
    Thanks a lot for your support!

    1. ColorIndicator is a 2d Sprite which shows a changin background color. Its in background with Order in Layer=1
    2. Canvas (order in layer 6) holds the UI labels you see on top (Score + Lifes). I could probably somehow place the other texts here too, but I want them to be part of the Target-Prefab and need to position them based on the Targets position, which I found pretty complicated because the canvas uses different coordinate system then the sprites.
    3. Currently in the shown setup each of the Targets (a simple 2d sprite, Order in Layer=4) covers 1/4 of the display. The targets color is usually set to 0% opacity, as it should be mainly a click target but not display something (except in some situations where I would flash some color with them and set the opacity temporarily to >0%) - except of a text on it (which is what I'm failing at).
    4. The Targets are prefabs.
    5. The TargetTxt (Text Mesh) should be shown in the middle of each target (even if the number of targets increases, e.g. I could add 6 covering each 1/6 of the display) ON TOP of it.

    But right now the TargetTxt shows behind everything. I can only see it when removing/hiding the ColorIndicator in background (as all other elements are anyway invisible. If I set them visible they are also in front of the text, including the parent of the text). I don't get how I can change this. The parent object is in a layer above ColorIndiactor. I have no "order in layer" property in the TargetTxt. But it shows behind its own parent and behind any other object...

    I tried playing around with the z-values but without luck... This is a 2d application.
     
  8. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    try textmeshpro, it has order in layer in the canvas settings
    or make packge from your project (if it has nothing of "Top secret", then I can look at it on my pc (assets-export package)).

    try to change order in layer on the sprite to negative (I think, this is target clone)
     
    Last edited: Nov 25, 2018
  9. NabeelGS

    NabeelGS

    Joined:
    Apr 9, 2021
    Posts:
    1
    yes changing the order in layer worked. Great help thanks