- Home /
Clickable object behind clickable HUD element with Unity UI
I have a clickable 3d object in the scene rendered by the main camera. The main camera has a PhysicsRaycaster attached and the object a normal box collider for example so its clickable as wanted.
Then I add a transparent HUD with a button for example which should be rendered always on top of normal 3d scene, so a HUD gameobject with a canvas which contains the button at some place on the screen.
My question is how do I setup the canvas so that I can click the button in the HUD but still are able to click the 3d object in the scene as well. Here are the ways I already tried:
Set Canvas to screen space overlay plus a GraphicsRaycaster next to the Canvas. The HUD is clickable but all clicks are intercepted by the GraphicRaycaster and never reach the PhysicsRaycaster of the main camera so the 3d object is not clickable anymore
Set Canvas to screen space camera, now the HUD neets to be placed very close to the main camera (canvas->plane distance) otherwise the UI is rendered behind the 3d objects. Placing the Canvas so close to the main camera will again block all rays to hit the 3d objects in the scene
So instead keeping the canvas->plane distance at a high distance but rendering the canvas with a separate camera on top of the main camera is the closest I got. The HUD is always on top of the 3D objects and both the HUD elements and the 3d objects are clickable excapt if a clickable 3d object is now physically in front of the HUD the 3d object is clicked and not the HUD element.
Its probably some stupid mistake by me but I can't figure out how to do this the right way :/
Answer by JoshuaMcKenzie · Nov 21, 2015 at 03:20 AM
there are a couple ways you can go about this. but the quickest and easiest way that I've found is to use canvasGroup components.
have a canvas group component on the Canvas that doesn't block raycasts. Then in a panel that has a button (or group of buttons) you want detected have another canvas group that blocks raycasts and ignores parent.
Answer by AmunTech · Nov 21, 2015 at 02:24 AM
have you tried to uncheck the raycast target checkbox on the images? I know that this can block mouse click on ui objects placed behind if its checked, but i dont know if its the same for 3d objects.
Your answer
Follow this Question
Related Questions
How can I select a UI element with a raycast from another UI element? 2 Answers
Canvas: On hovering over Buttons: Wrong Buttons activated 2 Answers
If button highlighted 2 Answers
Problem with a button 2 Answers
Cannot click UI button. 4 Answers