Search Unity

Bug Nested canvas elements may get corrupted on Unity 2021.3

Discussion in 'UGUI & TextMesh Pro' started by DanielRN_0101, Jul 21, 2022.

  1. DanielRN_0101

    DanielRN_0101

    Joined:
    Apr 9, 2019
    Posts:
    6
    After upgrading our project's Unity version from the 2020.3.13f1 to the 2021.3.6f1 we noticed an issue in the behavior of nested canvases (GameObjects with a canvas component that are children of another GameObject with a canvas component), getting 'corrupted' when some actions are executed (it was working fine on 2020.3.13f1). We created a blank project and performed some testing.

    This corruption causes multiple problems:
    • UI elements inside the nested canvas are invisible or glitchy when seen in the Scene view.
    • UI elements inside the nested canvas ignore UI events: for example, buttons can no longer be pressed, they ignore any user interactions with the mouse/finger
    • Corrupted nested canvases might be rendered in the wrong order, ignoring the hierarchy order even if their sort order is the same
    There are at least two ways of provoking this corruption:
    • After disabling a nested Canvas component (both from the inspector or by code with 'canvas.enabled = false;') the corruption will appear if the canvas is enabled by code ('canvas.enabled = true;'). There is no problem if the canvas is enabled manually from the inspector.
    • Deactivating the nested canvas GameObject (both from code or with the inspector) and reactivating it (both from code or with the inspector). Performed by code with the 'SetActive' method.
    A quick way of reproducing this issue is creating a nested canvas and a Button inside it. The button will be clickable as normal. Then while still in Play mode, from the inspector, deactivating and activating the nested canvas. The button will no longer be clickable. The hierarchy is:

    - Canvas (Canvas component)
    - NestedCanvas (Canvas component)
    - Button (Button component)

    I searched on the forums but I found no posts about this matter. Thanks in advance.
     
    joshcamas and sugekoma like this.
  2. adbourdages

    adbourdages

    Joined:
    Jul 8, 2012
    Posts:
    75
    DanielRN_0101 likes this.
  3. DanielRN_0101

    DanielRN_0101

    Joined:
    Apr 9, 2019
    Posts:
    6
    Yes, it seems to be the same problem. I will try tomorrow toggling the 'sort override' checkbox on and I will provide feedback of the results on this post.

    Anyways, I guess this issue will be addressed in the next Unity releases. Thanks!
     
  4. DanielRN_0101

    DanielRN_0101

    Joined:
    Apr 9, 2019
    Posts:
    6
    So I just checked it out and it seems that toggling that checkbox on does fix the problem, I haven't found any additional issues and both ways I listed for reproducing the corruption are no longer working. So yeah, that's a workaround.

    In our case, we would have to change many prefabs and scenes in order to implement this change, so I think that downgrading to the 2021.3.5 or waiting for a fix will be better.
     
  5. kcastagnini

    kcastagnini

    Joined:
    Dec 14, 2019
    Posts:
    61
    Yes! If found this project breaking bug me too.

    Try to test this set up please:
    RootCanvas
    -> CanvasContainer
    -> Button
    (Button is a child of CanvasContainer and CanvasContainer a child of RootCanvas).

    Both RootCanvas and CanvasContainer has a Canvas component (plus Scaler, Graphic Raycaster, etc).
    If I disable and enable the canvas component of the CanvasContainer object FROM SCRIPT, the button is not longer interactable, I need to disable and enable it from the editor in order to work.

    This issue doesn't happen if I remove RootCanvas and let CanvasContainer be the root object.

    This is an extremely serious issue that is breaking my whole UI structure, fix this ASAP, thanks.

    EDIT: a temporary fix for this issue it to set Canvas.overrideSorting to true for each sub canvas
    (https://forum.unity.com/threads/can...broken-after-upgrade-to-unity-2021-3.1308642/)
     
    Last edited: Jul 26, 2022
  6. Vygar

    Vygar

    Joined:
    Dec 20, 2015
    Posts:
    23
    I just encountered this issue in 2021.3.7 which broke a fairly complex UI Structure. Toggling Override Sort order returns some functionality but anything implementing Drag/Drop and IPointerHandler implementations are now non-functional. Had to revert to a previous version.....
     
  7. aromana

    aromana

    Joined:
    Nov 11, 2018
    Posts:
    137
    Yes, I've also just been burned my this. Mind-blowing that such a massive regression could happen silently on a point update of an LTS. Has anyone found more information about this issue? I also independently discovered that toggling sort order fixes the issue. Wtf Unity....
     
    kcastagnini likes this.
  8. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
    This is a serious issue.
     
    erenaydin likes this.
  9. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,282
    Last edited: Aug 19, 2022
    Thermos likes this.
  10. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
  11. Tortuap

    Tortuap

    Joined:
    Dec 4, 2013
    Posts:
    137
    Well there are still many issues on child Canvas... I just realized that on 2021.3.9f1, nested Canvas got renderer twice. Delete the Canvas component and the UI is rendered normally. You can see that with transparent Image.

    And still those really annoying warning message in the Editor when hitting Play ("SendMessage cannot be called during Awake, CheckConsistency, or OnValidate (Moves: OnCanvasHierarchyChanged)").

    What's going on guys ? What changes did you do to break so many things with nested Canvas ?
    And how is that possible for so many bugs to get into a LTS release ???
     
  12. Mafutta

    Mafutta

    Joined:
    Sep 30, 2014
    Posts:
    45
    This still happens in 2021.3.16 through even 2021.3.21 LTS. Fix this asap!
     
    erenaydin likes this.