Search Unity

Annoying bug with child canvasses

Discussion in 'UGUI & TextMesh Pro' started by hessel_mm, Jan 30, 2015.

  1. hessel_mm

    hessel_mm

    Joined:
    Mar 12, 2014
    Posts:
    44
    When I create a canvas with a bunch of child canvasses like this (ignore the names for now):

    Where the child canvasses are set up like this:

    And then press play or save the scene, specific child canvasses' recttransform are changed (and the changes persist when exiting play mode):


    The weird thing is that it is always the same children that are affected (as you might have guessed the ones with the "_Buggy" suffix). Reordering them doesn't change the child canvassed being affected.

    I have a really, really, terrible workaround to disable the canvas component and then enable it with a script after one frame.

    The reported bug is here: http://fogbugz.unity3d.com/default.asp?667258_s8q7046cir6m6b5f

    I'd love to know if there is something (proper) I can do to work around this because right now it randomly breaks part of my UI.

    (ps this didn't happen in 4.6.1p1 and I noticed it in 4.6.1p5 and it still happens in 4.6.2)
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    That definitely looks like a bug. Interesting find.
    However I would also point out it is unlikely you would ever need that many child canvases.

    You only need to use a canvas if you need to specify a different scaling pattern (the Canvas Scalar), which you seem to have removed from all the children anyway. Or if you want to use different custom raycast systems on a specific canvas. Otherwise it is better to group objects using Empty GO's for containers.
     
  3. hessel_mm

    hessel_mm

    Joined:
    Mar 12, 2014
    Posts:
    44
    Well, I have a child canvas for each group (interface screen/section) so I can set the alpha in their Canvas Group component to 0. If they didn't have a Canvas component on them, they'd be drawn with 0 alpha anyway cause a significant amount of overdraw. Having the canvas component on there causes some sort of optimization to trigger and not render the entire groups with 0 alpha.

    Of course, there are ways to set this up differently (and those are probably smarter) but the thing is that this used to work fine and this project is almost finished. So, reorganizing everything to work around this bug is not really ideal :)

    edit: And I didn't change anything on those canvasses, those are vanilla, out-of-the-box Canvas components; they change their inspector interface when they are parented to another Canvas.
     
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    A CanvasGroup doesn't need a Canvas. It can be on any GO that is a child of at least one Canvas :D

    So you can have
    * Canvas
    -> EmptyGO (with CanvasGroup)
    -> image
    -> Text
    -> etc
    And altering the CanvasGroup alpha will affect all it's children alpha values.

    Still a bug though
     
  5. hessel_mm

    hessel_mm

    Joined:
    Mar 12, 2014
    Posts:
    44
    I know CanvasGroups don't need a Canvas to work (I use them all over the place). The point is without the Canvas there all elements in the group will be drawn even if the alpha is 0, if the Canvas is there the entire group won't be drawn at all if the alpha is 0. This is quite a major difference on platforms that are sensitive to overdraw (i.e. mobile).
     
  6. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    If I'm reading that right, then it sounds like a bug. Worth logging that as a separate issue to the one above
     
  7. hessel_mm

    hessel_mm

    Joined:
    Mar 12, 2014
    Posts:
    44
    Whoo, it has been fixed in 4.6.2p1 :)
     
    Last edited: Feb 11, 2015
  8. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    Progress, great stuff