Search Unity

Feedback UI Environment doesn't work for prefabs with a canvas on their root

Discussion in 'Prefabs' started by TheValar, Mar 15, 2019.

  1. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    754
    Currently if you have prefabs with a canvas on them (at their root) when you open them up in edit mode they are not put inside the UI Environment that is set in Project Settings.

    I'm not sure if this is by design or a bug but it does present a problem for using canvas scalers. Rather than being able to put a canvas scaler in my UI Environment scene that will be consistent for all UI prefabs I have to manually copy it and apply it to every canvas prefab.
     
    Jes28 likes this.
  2. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,612
    Is the Canvas on the Prefab in question used in your scene as a root Canvas or a nested Canvas?
     
  3. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,612
    We have an upcoming fix where nested Canvases get treated as nested Canvases in Prefab Mode too. This means they will be opened with a different Canvas as parent, whether via the UI Environment scene (if one is set) or an automatically generated Canvas.

    If on the other hand your Prefab is a screen space Canvas that's a root Canvas, then it will be treated as a root Canvas in prefab Mode too, and not use the UI Environment scene.
     
  4. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    754
    The canvas in question is a root canvas as far as the prefab is concerned, but when it is instantiated in-game it is nested under a root canvas that contains all the UI.

    when you say "nested Canvases get treated as nested Canvases in Prefab Mode too." what does this mean? how is a "nested canvas" on the root of a prefab get differentiated from a "root canvas" on the root of a prefab?
     
  5. runevision

    runevision

    Unity Technologies

    Joined:
    Nov 28, 2007
    Posts:
    1,612
    If a Canvas is a screen space root Canvas when you create it, it will have its RectTransform properties driven by the Canvas. These driven properties are all serialized as 0, whereas a Canvas that's being used as a nested Canvas will not drive the properties of its RectTransform, so they're highly unlikely to all be 0. In the upcoming fix we use that information to deduce if a Canvas should be treated as a root Canvas or a nested Canvas when in Prefab Mode.
     
  6. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    754
    cool that definitely sounds like it would solve the issue for me! Can't wait to get a hold of it
     
  7. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    754
    @runevision is this fix in yet by any chance? We just updated to 2019.2 and for some reason I was expecting it to be there but it doesn't seem to be. Is there an issue tracker item I can monitor for this?

    Edit: Scratch that it seems I can get it to work, but I have to change the canvas on the nested canvas prefab to be world space, then re-open it and fix it's rect transform settings. A bit strange but I'll take it