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 prefabs and UI canvases

Discussion in 'Prefabs' started by DigitalContinue_MS, Oct 10, 2018.

  1. DigitalContinue_MS

    DigitalContinue_MS

    Joined:
    Dec 9, 2016
    Posts:
    32
    I have been looking forward to nested prefabs for a long time, and finally trying them out today. I do have a question about Canvas prefabs. In my project I have a menu system canvas, which i have a bunch of different canvas prefabs attached each with a bunch of UI.

    The issue i am having is that when i go to edit one of the child canvas prefabs, when returning to the project view, the scale is set to 0. When looking at the prefab in the prefab view it shows it at one, but every time sets it to 0 after leaving the editor.

    Is there a solution for doing Nested canvases right now?

    I am currently on 2018.3.05b

    Thank you for any help
     
    AndreFace likes this.
  2. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Can you file a bug report with repro project and repro steps?
     
  3. hunterofakara

    hunterofakara

    Joined:
    Oct 4, 2018
    Posts:
    21
    It seems to avoid this in the meantime you'd either need to have a non-canvas object as the prefab root when editing (even just a blank gameobject as the parent, to ensure the UI prefab environment appears with it's own canvas) or else have some script to force the values to save correctly when saving/exiting prefab mode.

    The same situation happens if I drag a prefab canvas that was made as a child to the root of a scene - It shows 'Some values driven by Canvas' on the recttransform (itself instead of a canvas above it) and displays generated numbers that don't serialize as shown when you apply changes.
    In prefab mode, it doesn't even detect the changes until you change something else and save.

    I had a similar problem after upgrading where I'd previously relied on a ContentSizeFitter saving it's applied properties to the prefab.
    Any such prefabs I saved after updating to the beta had unconfigured transforms instead.
    I was able to workaround that by using a script to load the prefab and force a layout rebuild then save it again, but it relied on very specific behaviour (fitter's SetLayoutHorizontal function stopped it tracking changes temporarily, allowing me to save before it reset everything).
     
    AndreFace and DigitalContinue_MS like this.
  4. DigitalContinue_MS

    DigitalContinue_MS

    Joined:
    Dec 9, 2016
    Posts:
    32
    Thank i submitted a report about the issue. I did also notice that it will change the anchor type from stretched, to bottom left
     
  5. loktherut

    loktherut

    Joined:
    Jan 11, 2017
    Posts:
    1
    Also currently struggling with same problem. We're currently on 2018.3.7. Anyone found any solution?
     
  6. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    For information, we have a fix in the pipe. I don't know yet what version it will make it into. This is the release note for when it ships:

    Fix RectTransform properties of nested Canvas getting incorrectly modified upon entering Prefab Mode.
    Ensure nested Canvases are always treated as nested Canvases in Prefab Mode too. Root World Space Canvases can get treated as nested Canvases in Prefab Mode too due to lacking information, but this will still have fewer downsides than if nested Canvases got treated as Root Canvases.
     
    SugoiDev likes this.
  7. smallstep

    smallstep

    Joined:
    Jan 25, 2016
    Posts:
    34
    I have the same problem as OP (Unity 2018.3.12).

    Create Canvas (with Screen Space Camera and Scale with Screen Size, settings)
    Make it a prefab
    Make a canvas instance in editor
    Nest a 2nd canvas instance, bellow 1st instance
    Edit canvas prefab (whatever change)

    Result: child canvas loses scaling (0,0,0) and anchoring (bottom left). Any content disappears.

    NOTE: This has nothing to do with prefabs. It has to do with Canvas parenting/scaling. I tried to nest two canvas without prefabs and it works, until you re-parent the child canvas to be at the same level with the parent (or begin with same level and then make the one child of other). Again the scaling/anchoring breaks.

    This not only makes working with canvas impossible, it also breaks any work you have done in a complicated project, if you forget and edit a canvas prefab!

    I see similar issues dating back to 2014, with several "fixes", eventually breaking the specific functionality again and again till today. I am most interested in finding a way to bypass the problem, rather than waiting for yet another (temporary) fix. Rooting the canvas with an empty gameobject doesn't seem to work...

    Any ideas?
     
  8. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    The bug report we have on this issue (https://issuetracker.unity3d.com/is...et-after-modifying-and-exiting-in-prefab-mode) is fixed in 2019.1 and in 2018.3.12.

    If you're still seeing issues in 2018.3.12 or later, we'll need a new bug report that does repro (since the original one does not). It's likely a (somewhat) different issues even though it sounds similar.
     
  9. smallstep

    smallstep

    Joined:
    Jan 25, 2016
    Posts:
    34
    It seems to work almost as expected in 2019.1. I'll report back anything significant. Thanks!
     
    runevision likes this.
  10. Daegit

    Daegit

    Joined:
    Nov 20, 2015
    Posts:
    32
    2019.2.8f the bug isnt fixed.
     
  11. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,892
    Or it's a different bug with similar symptoms. We'll need a bug report for this, as we don't have bug reports for this issue that still reproduce.