- Home /
The question is answered, right answer was accepted
UI Click pass through
I am making a context menu and when this menu is called up I have an invisible panel in front of everything except this menu. I have a click handler on this invisible panel. Right now, the invisible panel is getting the clicks and eating them(blocking them). What I would like it to is handle the event, but not block it, so the rest of the UI can get clicks as well.
If I turn off "Raycast Target" on the invisible panel's Image component, clicks go through, but they do not get handled.
Is there a way to have a UI element get handled but not block other elements?
I can't think of a way to bubble the event further - so I'd be inclined to get creative...
You can fire your own ray through the screen, and assu$$anonymous$$g your UI is added to the appropriate layer - you can get a handle to all the UI elements you "touch".
Then handle each one independently. The only issue though is that this does not use the UI message system, so sounds clunky...
Why do you need a transparent panel to get clicks but not block them? That's kind of contraproductive. ;)
Wouldn't it be easier to simply check if the the mouse is clicked & the context menu is not clicked? Because this means logically, that anything in the "background" is clicked. Example code:
if(click & click.tag != "Context$$anonymous$$enu")
{
Close$$anonymous$$enu();
}
Using Tags is just one simple way to give you an example.
Additionally I's like to mention, that this is a "HowToDo" question for Unity Forums, not for Unity Answers.
Unity Answers is for problems with Unity functions that behave unexpected.
Check out the Frequently Asked Questions and the User Guide to avoid this in the future.
Is there a way to have a UI element get handled but not block other elements?
This would the question you should google or search Unity Forums for.
Google might point you to Unity Forums anyway :)
Have a nice day.
Yes, but I need somewhere to see what's been clicked. If I just use something like Input.Get$$anonymous$$ouseButtonDown, that won't do a ray cast to see what's been hit.
I suppose I could use something like ian_sorbello's answer and do my own ray cast.
I was able to get it working as I wanted by checking for Input.Get$$anonymous$$ouseButtonUp in the Update loop- and then destroying the object no matter what is hit. Because Desroy is delayed, any buttons hit on the menu will still execute.
Answer by jkramar · Nov 19, 2015 at 02:34 PM
Have a look at the CanvasGroup Component. It has at least part of the functionality you are looking for.
Follow this Question
Related Questions
Send inputfield entries via email 2 Answers
Changing UI for network chat 1 Answer
Two dynamic dropdowns from one source list 0 Answers
Load different render textures into Raw image object 0 Answers