Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Nested Canvases do not Save Anchoring Settings

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by koba0100, Feb 11, 2015.

  1. koba0100

    koba0100

    Joined:
    Nov 23, 2014
    Posts:
    2
    1) What happened?
    Nested UI canvases do not seem to retain their anchoring settings (as set by the rect transform component) upon saving->reopening or hitting play. This bug is new as of either 4.6.1 or 4.6.2. Everything was perfect in 4.6.0!

    2) How can we reproduce it using the example you attached?
    CanvasNested is a child of Canvas. If you try to modify the anchor preset of CanvasNested in any way, and then hit play, it will always reset to "bottom left" and be really wonky in general.

    (Submitted as issue 671550)

    I wish I could find some workaround for this issue beyond recreating everything, it has really messed up my game's menus!
     

    Attached Files:

    Last edited: Feb 12, 2015
  2. Skoon

    Skoon

    Joined:
    Oct 28, 2014
    Posts:
    2
    I just upgraded to 4.6.2 and am running into the same issue. When I run the scene, it seems to revert all of the changes as well.

    Have you found a workaround that sticks?
     
  3. koba0100

    koba0100

    Joined:
    Nov 23, 2014
    Posts:
    2
    Beyond reworking everything to avoid nesting canvases, I have no workaround. It always seems to reset to some arbitrary position when I run the scene, Certainly not even being properly anchored at the "bottom-left" like Unity says. Hopefully this bug will be fixed!
     
  4. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    451
    I have a work around that seems to work for me so far. Instead of adding a Canvas like you normally would through the gameObject or create menus. Add a panel then remove the image and canvas render components, then add a canvas component to the object. The root canvas has a CanvasScaler component attached, when you add a child canvas it also adds another CanvasScaler to that one, which is where I think the bug happens. It does have a message saying "Non-root canvases will not be scaled." but that doesn't seem to be the case.

    I tested this with your test project and used the work around to fix the issue. You will still need to add things like GraphicsRaycaster if you need it, just avoid adding a CanvasScaler to non-root canvases.
     
  5. tjlarch

    tjlarch

    Joined:
    Sep 9, 2012
    Posts:
    1
    Yes, this is awful. I've also noticed that disabling a canvas renderer does not disable the children canvases. I'll have to work on something else for now...
     
  6. Agent654

    Agent654

    Joined:
    Dec 11, 2012
    Posts:
    8
    This issue has come back as of 5.2.0f3 - I'm rolling versions back to see if I can proceed...
     
  7. Apoll0

    Apoll0

    Joined:
    Jun 11, 2015
    Posts:
    16
    Confirm this issue in 5.2.1f1 :(
    BTW, Chris Trueman's solution works.
     
  8. S4UC1SS0N

    S4UC1SS0N

    Joined:
    May 29, 2014
    Posts:
    28
    Thanks for this workaround, i'm sure this will be refixed quicly.
     
  9. omsolari

    omsolari

    Joined:
    Apr 7, 2014
    Posts:
    2
    +1 on this. Nesting objects is critical for achieving complex game mechanics. I hope this bug is fixed soon. Still exists in Unity 5.2. Unity, any word on this?
     
  10. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    451
    I have not found a need to nest canvases after this post I made. I have now changed it to add an empty GO with a RectTransform to the main Canvas(Just add an empty GO as a child to the canvas and voila). I then use that like I would a nested canvas setting the anchors and size. You can add any UI component to it like a CanvasGroup, Layout or disable that GO and all the children follow along. My menu system does this and it works very very well. I also used the same technique in a solitaire game made entirely in the UI, and no problems, in fact the drag and drop system made me able to get it all working in no time.

    Canvases DO NOT need to be nested, don't get me wrong I think Unity should address this issue. They did and it came back. Simple fix really; if a canvas is being added to another canvas only add it with the canvas component and not all the other stuff added normally. Bottom line is that it isn't needed though as an empty GO does the same thing with less processing and probably less draw calls too(no canvas component to process).
     
  11. Green-Sauce-Games

    Green-Sauce-Games

    Joined:
    Mar 27, 2014
    Posts:
    69
    I have the same problem on 5.4.0f1! Is this a regression?

    Please, this is making me crazy!
     
  12. shaunmitchell84

    shaunmitchell84

    Joined:
    Dec 17, 2013
    Posts:
    3
    I had the same issue on 5.4.0f1

    I simply made the offending nested canvases into an empty game object. You can add the empty child to the root canvas and then drag any of your UI elements into that instead, then copy any components you already had on the nested canvas (not the canvas component itself obviously) onto your new empty GameObject.

    Solved for me.
     
    Last edited: Jul 22, 2016
  13. Steve_Unity

    Steve_Unity

    Joined:
    Jan 19, 2014
    Posts:
    7
    Thank you for this solution.
    I am literally in my first hour of using Unity and was beginning to think that it is counter-intuitive and not worth the effort!
    I have a habit of finding bugs in the things I try to create.
     
  14. Steve_Unity

    Steve_Unity

    Joined:
    Jan 19, 2014
    Posts:
    7
    Just to add to this, sub-canvasses are important. Here is an extract from UI design performance...

    Canvases are responsible for combining their constituent geometry into batches, generating the appropriate render commands and sending these to Unity’s Graphics system. All of this is done in native C++ code, and is called a rebatch or a batch build. When a Canvas has been marked as containing geometry that requires rebatching, the Canvas is considered dirty.

    Geometry is provided to Canvases by Canvas Renderer components.

    A Sub-canvas is simply a Canvas component that is nested inside another Canvas component. Sub-canvases isolate their children from their parent; a dirty child will not force a parent to rebuild its geometry, and vice versa
     
  15. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Happening in 5.4.0f3 for me.... grrrr
     
  16. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Fixed my issue by removing the canvas and graphicsraycater scripts and re-adding them.... The Transform component in unity 5.4 was rewritten so I assume it was just a project upgrade issue
     
    breban1 likes this.
  17. breban1

    breban1

    Joined:
    Jun 7, 2016
    Posts:
    107
    I have the same exact issue going from 5.3.4f1 to 5.4.0f3. @image28 I'll try your suggestion and reply back here. I have about 15-20 different canvas objects, so this is going to be a pain. Rewriting a component like Transform seems like a pretty big risk considering every object contains one, wow.
     
  18. breban1

    breban1

    Joined:
    Jun 7, 2016
    Posts:
    107
    Nested Canvases are very important for performance with dirty UI areas as @Steve_Unity posted below. Empty GO's are not an option.
     
  19. breban1

    breban1

    Joined:
    Jun 7, 2016
    Posts:
    107
    This SEEMED to work for me for one object, but the next one I tried it did not work on. The object is scaled strangely, and somehow it looks like the complete GO is alpha blended now. Unity needs to fix this. Looks like I'm stuck on 5.3 for now.
     
  20. breban1

    breban1

    Joined:
    Jun 7, 2016
    Posts:
    107
    Well, I ended up REMOVING the canvas, raycaster, and scalar if they were on a canvas object, then adding them back through the editor and it works for the most part. The scale on a few of the objects were still incorrect doing this, so I reset them manually.

    Just wanted to follow up on what worked for me. Oh, and thanks @image28
     
    Last edited: Aug 11, 2016
    image28 likes this.
  21. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    451
    Yeah that statement was made when I didn't fully understand how canvas's and how uGUI worked. After having to work through some issues I understand the need for nested canvas's on more complex UI's.
     
  22. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    114
    Same issue here. I haven't tried removing and re-adding the nested canvases, because I've got a number of them and it's not really an ideal solution with all that manual work. Unfortunately, this is preventing an upgrade from 5.3 to 5.4, ugh.
     
  23. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    so long as they don't all have different settings you can type t:Canvas into the search bar, them remove and re-add them all at once.
     
  24. adamt

    adamt

    Joined:
    Apr 1, 2014
    Posts:
    114
    Seems like that worked. Brutal, though, and I'm sure I missed some (unfortunately, t:Canvas doesn't seem to work in the project view, which is a bummer since all our UIs are dynamically instantiated at runtime). Thanks for the tip, though!
     
  25. breban1

    breban1

    Joined:
    Jun 7, 2016
    Posts:
    107
  26. spelkraft

    spelkraft

    Joined:
    Nov 26, 2015
    Posts:
    1
    I just upgraded to 5.4.1f1 from 5.3.5p2 and discovered this bug. Super annoying! My fix (until it's gets fixed for real) is to create a script that corrects the rectTransform settings on Start. That way it kind of fixes what unity destroys.
     
    PoppinFresh likes this.
  27. harady

    harady

    Joined:
    Mar 7, 2015
    Posts:
    1
    I just upgraded to 5.4.2f2 from 5.3.6f1 and discovered this bug too.
     
    PoppinFresh likes this.
  28. Xavier78

    Xavier78

    Joined:
    Oct 13, 2013
    Posts:
    10
    How is this still an issue, I am running 2017.3.0f3 and they are still messing up, what I have found it to be is a RectTransform that is a child object. They just move all over the place, I actually made a script to change their position back on start up.
     
  29. SergeantBiscuits

    SergeantBiscuits

    Joined:
    Jul 22, 2012
    Posts:
    13
    2018.1.0b8 checking in here with the issue...
     
    firejerm likes this.
  30. firejerm

    firejerm

    Joined:
    Dec 28, 2012
    Posts:
    38
    2018.1.b7 Its still a thing.

    With me, I can set everything up in scene, script set active true and false. Hit play, its fine. Make a prefab....canvases fly all over the place. Or, edit the Ui, goes bonkers.

    doesn't do it with panels though.
    So 1 canvas, 5 panels, 4 panels nested in each of them, each of those 4 has images and buttons. All good.
    Do the same but use a bunch of canvases and it goes wacky. Are...are we just misunderstanding Unity's intentions of using canvas? Canvas > mainMenuPanel> Options panel> options buttons , levelSelectPanel> levelListPanel> level buttons.
    Like referencing to real world: the UI Canvas was supposed to be like a computer monitor.
    So you have monitor, Browser, tabs in browser, page in tabs, buttons and stuff in page.

    But instead we are trying to put a monitor screen inside another monitor screen ++. And the results is the Editor is trying to break through the 4th dimension and more.

    At least thats how I have been treating it.
     
  31. killakiwi

    killakiwi

    Joined:
    Sep 5, 2013
    Posts:
    16
    Still present in 2018.3.0b2
     
  32. ZhavShaw

    ZhavShaw

    Joined:
    Aug 12, 2013
    Posts:
    121
    Still present in 2019.1