Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

uGUI and Input handling

Discussion in 'UGUI & TextMesh Pro' started by ibyte, Dec 17, 2014.

  1. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,023
    Based on several tutorials I have designed my UI so that there are specific canvas's that cover the entire screen area in order to have certain UI elements stay off screen at any resolution/aspect ratio and have them pivot in when needed.

    I have some older code that utilized Input.GetMouseButton and both tthe UI and my 3D objects are responding to clicks when the mouse is over a UI element that also happens to be in front of a 3D Object.

    Adam suggested that the 3D objects should use currentEventSystem.IsPointerOverGameObject() if possible but this is always true in my case due to the panel taking the full screen space.

    One possible work around he also suggested was to move all non interactive UI elements under a Canvas Group and set Block Raycasts to false but this does not seem practical for my particular setup.

    I need a way for these panels to do their job but be transparent to interaction without affecting the child controls.
     
  2. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,023
    Bump?
     
  3. brendan-vance

    brendan-vance

    Joined:
    Jan 16, 2014
    Posts:
    36
    The system is designed such that input events will fall through one canvas to another assuming there isn't some UI element blocking them (thus, IsPointerOverGameObject should only return true if the pointer is over an actual UI element rather than just any canvas).

    Do your canvases have an image component covering the entire area of the screen, or anything like that? If so, do they need to be there?
     
  4. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,023
    Hi Brendan, Thanks for the reply. My main foreground panel has an Image component but it is disabled (could be removed I expect). The other objects in the hierarchy used for placement are just rect transforms that are fully stretched.

    So I have a background Canvas and Camera (depth -1), I have a camera (depth 0) used for 3D objects and then i have a Forground Canvas and Camera (depth 1)
     
  5. brendan-vance

    brendan-vance

    Joined:
    Jan 16, 2014
    Posts:
    36
    It's possible that the image, even if disabled, will interfere with the raycasters; I've had that problem before.
     
  6. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,023
    Hmm didn't seem to help. I should setup a simple scene to see if I can repro it.

    Any idea how I can tell which object it's actually hitting?
     
  7. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,023
    When i use the code in this post any child controls do not respond to clicks.
     
unityunity