OnPointerEnter blocked by something
I have my project setup like this:
- Main Camera
- Physics 2D Raycaster
Event Mask: Everthing
- Physics 2D Raycaster
- Canvas
- Graphic Raycaster
Blocking Objects: None
Blocking Mask: Nothing
- Graphic Raycaster
2 Objects setup:
- GameObject
Sprite Renderer
Rigidbody 2D
Circle Collider 2D
(my GO script)
- UI
Image
Button
(my UI script)
In both my GO and UI script, I add events like OnPointerEnter,etc. Everything work fine. I have my pointer enter event on both object. But when I use a joint to drag a GO object and move to top of the UI object. My UI object OnPointerEnter blocked. I search on web and everybody ask for blocking raycast on GO to UI. But I need the reverse, I want both GO and UI receive all events normally when any object overlap. Any hints?
Not sure if i get it right, but maybe just add triggers to your UI to trigger the event in game object ?
Hi Zynek, Thanks to your advice and it seems is a way out. But when I add a rigibody2D and 2Dcollider(is trigger) on the UI object. The OnTriggerEnter2D didn't received event. I don't know if I do something wrong. Is it work to add trigger system in unity UI? P.S. my GO object already implement trigger system and work fine.
Thanks Zynek. the trigger system not work because I adding them as child of UI (seems my setting problem). But when I add them as component of UI, everything fly.
Deactivate option "Raycast Target" in the UI elements that could block the Physics 2D Raycaster.
Answer by philipyeung · Nov 06, 2016 at 11:40 PM
Finally get what I want by taking Zynek's suggestion. I add rigibody2D(isKinematic and Freeze xyz) and 2Dcollider(is trigger) as component in UI object. OnTriggerEnter2D receive my GO collider and done. But I still curious why I cannot make both GO and UI get my pointer/touch OnPointerEnter.
Answer by Zynek · Nov 07, 2016 at 07:35 PM
I´m sorry i misled you. What i meant is to add Event Trigger to UI as i did in this picture:
U just add pointer enter and pointer exit events and set methods you want to call when it occurs. In my case im calling method that sets boolean onGui to proper value.