Search Unity

Nested canvas issue in 5.2

Discussion in 'UGUI & TextMesh Pro' started by keht, Sep 24, 2015.

  1. keht

    keht

    Joined:
    Oct 4, 2014
    Posts:
    6
    Hi,

    I have a problem with nested canvases after updating to 5.2




    Why "Red" image not moving on drag? As expected, you can see moving selection border for image in the scene view, but position of rendered object is not changing.

    Is there any fix or workaround? Please help!

    upd: Sample project attached.
     

    Attached Files:

  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,689
    First off, why are you nesting Canvases like that? You should ONLY use a child canvas if you need to apply a different canvas scaler to it.

    For child panels, just use an Empty GO on a canvas which has a Rect Transform, it provides the same grouping capability.

    Try updating the hierarchy without the canvas and see if that has any effect.
     
  3. keht

    keht

    Joined:
    Oct 4, 2014
    Posts:
    6
    I need a nested canvas to change Order in Layer for some UI objects in my real game.
     
  4. dCoding

    dCoding

    Joined:
    Sep 9, 2014
    Posts:
    26
    I have the same problem, and only since 5.2.0, but was initially blaming Mecanim. I'm animating / moving UI elements, some of which are on nested canvases, but it turns out that is what was causing the issue.

    I didn't think I was doing anything wrong because Unity themselves say you can use nested canvases:
    http://docs.unity3d.com/Manual/class-Canvas.html

    "A single Canvas for all UI elements is sufficient but multiple Canvases in the scene is possible. It is also possible use nested Canvases, where one Canvas is placed as a child of another for optimization purposes. A nested Canvas uses the same Render Mode as its parent."
     
  5. Deleted User

    Deleted User

    Guest

    Disable the main, top level canvas...then..re enabled it...all of my child canvas elements, went back into place..so I then added that to my ui script....

    That was my workaround...

    But now I get a missing reference error in ui.dll...
    Weird stuff....5.2 does not like nested ui..but pro beta 5 rc3..had no such problems...

    P
     
  6. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    ya, i'm having some troubles with nesting in 5.2.1p1 too.

    if a child element of the main canvas has a canvas that overrides sorting, it and it's child elements get "stuck"... disabling them, and enabling places them where they're suppose to go, but doing this in script to correct it just isn't working, this only works via the editor.

    not really sure how to address this as I need those child elements to be able to drawn at a higher layer when selected (to become the upper most layer and over draw the others) as they change size. without the layer ordering, all the elements become mashed up on the same drawing layer.

    I've also tried setting those elements in canvas to the same sorting layer, and changing the layer order via script when they're selected and need to be scaled, but that isn't working either (especially since they get stuck were they're placed in the canvas when enabled to begin with)
     
  7. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    hmm... maybe because I forget to add a canvas renderer along with the child elements' canvas component...

    i'm testing this now... the code behind though is a little complex to deal with.


    [edit]

    yep, that fixed it for me... add a canvas renderer to the child component which uses a canvas component to override the sorting layer.

    i'll upload a video to show the differences, without that.. it's really broken.
     
    Last edited: Sep 26, 2015
  8. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    here's before after:
     
  9. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    So i remember fixing the nested canvas issue a couple weeks ago (shouldn't need a renderer as a child). I dont think it has made it way to 5.2 just yet though.
     
    super77gg and tswalk like this.
  10. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    you may have to watch from vimeo in HD to see it, but at times 00:37 & 00:56, when I select the "panelcontext" objects, you will notice only the canvas is present, whereas at time 01:48 the canvas renderer has been added.

    (unity version 5.2.1p1)

    I suppose it is just a workaround for now? but at some point your fix will be pushed... could you let us know here and i'ld be more than happy to run this through the ringer again . :)
     
  11. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    @phil-Unity

    I've noticed that when I have an element (say a panel), that has had a canvas (and renderer [a nested canvas basically]) added, with "Override Sorting" enabled and an order layer higher than its' parent canvas, the EventSystem will no longer process, pass, or recognize (which ever is the case) any pointer events (pointerEnter, pointerPressed.. etc.)

    The EventSystem is seeing these events, but just not passing them into the context of the nested canvas.

    Is this just by design? I can't figure out a way to deal with this...
     
  12. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Does the nested canvas have a GraphicRaycaster on it?
     
  13. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    nope... should it? :D
     
  14. tswalk

    tswalk

    Joined:
    Jul 27, 2013
    Posts:
    1,109
    I guess so.... that fixed it... thanks, been working on that for a good part of the day :)
     
  15. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    :) yea every canvas needs its own raycaster for its children to receive events. (at least all root canvas's)
     
    tswalk likes this.