- Home /
How to use the deselect Event Trigger?
I'm trying to make a panel get disabled (setActive(false)) whenever the player clicks outside of the panel. I looked up how to do this, and it pointed to adding an Event trigger of Deselect.
Whenever I test it, when I click outside of the panel, nothing happens. To see if the event trigger is actually working, I tried setting it to PointerClick and PointerEnter, and it works fine.
How do I use Deselect correctly? If it can't be used for the way I want it to, how should I do it?
Greetings,
I'd like to know where you're applying the deselect to. Do you have this code in a script attached to the panel itself? (That's were it should be, I believe.) Hope to hear more from you soon. :D
Ok, next thing to try. (Don't know it it'll work, but it's a thought.)
Try adding a:
Debug.Log("the panel has been deselected");
Line into your code right after the Deselect coding in your script.
Then, see if this message appears in your Console area, when you're testing the functionality in Play mode.
Then you can be sure that the Deselect code is working/not working.
I have a slight suspicion that perhaps when you click away from the panel, it's not actually deselecting, since whatever your clicking, may not be a "selectable"object which would cause your "Current selection" to remain focused on the panel. (Note, that this is just a theory...)
Hope this helps! :D
Answer by kevinleecarroll · Jan 20, 2015 at 07:24 PM
I was having the same problem. I could not figure out how to get the Deselect functionality to work. Then, kind of by luck, I figured out that Unity has a Selectable component that you have to add to the object that you are trying to Select/Deselect. After you add this component you should be able to receive Select/Deselect events by setting them up through the EventTriggers.
Can you help me set up where the components go? I just have a panel that needs to be closed when I click out of it and I need to know where the components go
The panel you want closed when you click out of it should have an EventTrigger component and a Selectable component. In the EventTrigger, you need to add a Deselect (BaseEventData) type trigger (same as adding PointerClick, but choose Deselect).
The rest should work similarly to a PointerClick event - set the panel as the object and have it call GameObject->SetActive(false) to close the panel.
Still doesn't do anything when I click out of it :/ Here's a picture of the panel setup: http://i.imgur.com/$$anonymous$$10vTCn.png
Do I need a Selectable component on any canvases that will be open behind my panel that needs to close?
Your answer
Follow this Question
Related Questions
How would I detect a right click with an event trigger? 3 Answers
[4.6 - UI] How to call an event with button when the pointer is up the button image. 1 Answer
4.6 UI Dynamic button event system PointerEnter, PointerExit, PointerUp etc. 1 Answer
How to wait click on button in my MessageBox analogue? 1 Answer
4.6 UI OnBeginDrag event handler doesn't seem to work. 1 Answer