Search Unity

Is there a way to set a parent to render after its children?

Discussion in 'UGUI & TextMesh Pro' started by ivoisbelongtous, Aug 21, 2014.

  1. ivoisbelongtous

    ivoisbelongtous

    Joined:
    Jul 28, 2014
    Posts:
    2
    Of course one of the features of the new UI system is to set the rendering order of a group of objects at the same hierarchical level by changing their position in the hierarchy view. However, I'm currently trying to make a gauge UI element, where an image element would cover two sliders. The image should be the parent in this case, but this means that it will be rendered first and will not be covering the two sliders as a result.

    I can think of a few workarounds such as making one of the sliders the parent, which feels intuitively wrong as well as complicating the positioning of the element, or using a mask of the inverse of the image - what a pain.

    So is there a proper way to solve this, maybe using scripting?
     
  2. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Maybe changing the Z position? (note, haven't tried this, just thinking)
     
  3. ivoisbelongtous

    ivoisbelongtous

    Joined:
    Jul 28, 2014
    Posts:
    2
    Great idea, but I just tried it and z positioning has no effect on the visual order of elements it seems. :(
     
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    A parent always render before its children. However, you can easily add an additional child (which should be the last child of the parent) which contains the image you originally had on the parent, and which is anchored and positioned to fully stretch with the parent so it overlaps one-to-one.