Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Bug Canvas click order using stacked camera

Discussion in 'UGUI & TextMesh Pro' started by rlapostolle, Jan 6, 2024.

  1. rlapostolle

    rlapostolle

    Joined:
    Jun 13, 2020
    Posts:
    2
    Hello!
    Here my setup:
    I have 2 scenes A and B.
    Scene A contains a main camera and a camera for UI stacked on the main camera.
    Scene B contains another camera for UI (same settings as the first UI camera), also stacked on the main camera of scene A.
    Both scenes contain a canvas using their respective UI camera (respectively named canvas A and canvas B). Canvas A use a lower layer & order in layer than the canvas B.

    What I observe is:
    I can click through the canvas B on buttons of the canvas A (even if there is a background image in canvas B that should block it) this behaves the same as if the canvas A was above the canvas B in term of layer. canvas B is always displayed above canvas A because of camera stacking, but the order in layer should make the click properly reach only the UI components of canvas B.
    In editor, if I move the canvas B into scene A and change it to use the UI camera A, then the behavior become correct: I cannot click on buttons from canvas A anymore.

    I really feel this is a bug, related to camera stacking or just the fact that I use 2 cameras for UI. Any thoughts on this ?

    PS: I experienced this with Unity 2021 LTS and 2022 LTS)
     
  2. rlapostolle

    rlapostolle

    Joined:
    Jun 13, 2020
    Posts:
    2
    After digging a lot more into it, I found the origin of the issue.
    The Depth (also named Priority in Inspector) was -1 for camera B and 0 for camera A. Leading to a wrong click order detection.
    The Depth description says it is only for rendering order of camera, but it is also used for input order detection.
    Therefore, the Depth is hidden when the camera is stacked (because the stack override the rendering order, which is the main purpose of Depth. But as Depth is also taken into account for UI click ordering, this should not be completly hidden, or just not used at all (the stack order could also be used to define UI click ordering).

    I still feel this is a bug from Unity.