Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Nested Canvases do not Save Anchoring Settings

Discussion in 'UGUI & TextMesh Pro' started by koba0100, Feb 11, 2015.

  1. koba0100

    koba0100

    Joined:
    Nov 23, 2014
    Posts:
    7
    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:
    7
    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:
    1,260
    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.
     
    vozcn and Ultroman like this.
  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:
    49
    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:
    1,260
    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:
    71
    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
     
    JPressley99 and breban1 like this.
  17. breban1

    breban1

    Joined:
    Jun 7, 2016
    Posts:
    194
    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:
    194
    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:
    194
    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:
    194
    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:
    1,260
    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:
    116
    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:
    116
    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:
    194
  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:
    41
    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:
    17
    2018.1.0b8 checking in here with the issue...
     
    firejerm likes this.
  30. firejerm

    firejerm

    Joined:
    Dec 28, 2012
    Posts:
    43
    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:
    22
    Still present in 2018.3.0b2
     
  32. ZhavShaw

    ZhavShaw

    Joined:
    Aug 12, 2013
    Posts:
    168
    Still present in 2019.1
     
    mr_blahblah and Rayeloy like this.
  33. mothacluckinjoe

    mothacluckinjoe

    Joined:
    May 8, 2017
    Posts:
    2
    After I changed the scaling anchor presets back to non-anchoring presets (centered), I found that the problem was for some reason within a prefab that was using the canvas. I had previously been trying to fix the problem with my canvas prefab, but after going to the larger prefab that used the canvas, I fixed the problem manually there. I don't understand what's going on with this but I'll take whatever gets me past it.

    Sorry if that's not clear, just trying to be helpful. If you have a prefab using your canvas, check the canvas instance in that prefab.
     
    ZhavShaw likes this.
  34. ZhavShaw

    ZhavShaw

    Joined:
    Aug 12, 2013
    Posts:
    168
    I do think it has something to do with prefabs. Regardless it would be nice to have some official fix.

    Still present in 2019.2.4
     
  35. JPressley99

    JPressley99

    Joined:
    Sep 21, 2018
    Posts:
    1
    Encountered this same issue in 2019.3. My game is ALL ui canvases which are enabled/disabled constantly to transition between "screens". Originally all overlay canvases, everything worked perfectly. Rebuilt it all for Camera Space so I could use particle effects (that was a whole other issue). Now anytime I disable a canvas the RectTransform anchor resets to bottom left and values are all over the place. Enable it again for use and it stay in that messed up state. Been a VERY maddening week of rebuilding and trying dozens of things that haven't fully worked.

    *Fingers Crossed* So far Image28's fix of removing the raycaster, canvas scaler, and then canvas on each of the child canvases and then adding those components back in reverse order worked like magic. Things are behaving predictably again.
     
    ZhavShaw likes this.
  36. JotaRata

    JotaRata

    Joined:
    Dec 8, 2014
    Posts:
    61
    Apparently it is still an issue in 2020.1.4
     
    ZhavShaw likes this.