Have a panel receive events but not block the raycast?

So I am using the EventSystem with a PhysicsRaycaster in the camera to get events such as clicks,drags, and other stuff in objects that have colliders.

Problem is that I also need to catch any event action in the screen when the user scrolls and drags to pan around and zoom with camera but I’m trying to add a UI panel to get those events but then it blocks any events that would hit the other objects with colliders since they are “under” the UI panel.

I’ve tried to set the physics raycaster to ignore the UI layer but it doesn’t work. I’ve also tried to have instead of the UI panel a big collider in the back of the camera and objects but then you don’t receive the events when you click over a collider.

Any ideas or suggestions?

I really like the event system and don’t really want to use the Input class if possible since the event system already handle multiple platforms.

I too (at first) started to use the event system to handle the gestures and implementing the handlers, but found as more layers and controls were needed it became a bit of a PITA to deal with… so I started using TouchScript and it is helping a lot.

Perhaps looking at that would help you out? touchscript.github.io/

Looks interesting!
But I would like it to be integrated with the Unity UI and they use the same Event system so I’m not sure how much it would help. Thanks for the suggestion, I’ll keep that one in mind for other types of projects :slight_smile:

I’m using it now with Unity UI… I’m even mixing 3D transform object “in” Unity UI with gesture controls :smile:

i’ll post a video here in a few minutes showing an example…

As an alternative solution you could use EventSystem.RaycastAll to get all of the elements at a certian point, then pass on the appropriate events with ExecuteEvents.

The other option is to break open the EventSystem code and write your own version that uses RaycastAll.

here’s a sample of using TouchScript with Unity UI, and some other hackery to gen shadows with 3d objects and managing spring joints (and switches)

https://vimeo.com/140484083

Thanks guys, I’ll take a look at both options!

hey @Rodiaz89 ,

I was reading this thread: Having GUI elements in front of *everything* ? - Unity Engine - Unity Discussions

and it may be possible to just implement ICanvasRaycastFilter set to false (from IsRaycastLocationValid) to not consume the cast… but still be able to handle events (atleast that’s what I gathered from what superpig mentioned)

??

[edit]

also looks like you may be able to add a ‘canvas group’ to the element and set ‘blocks raycasts’ (either statically or programmatically)

Just tried both options and they both either ignore it completely (so no event calls) or block like usual. I have seen that variable in the PointerEventData that is named ‘used’. I’ll look into that and see what it does.

Turns out that ‘used’ variable is only being used in the ‘InputField’ element for the UI, so nothing to do with the event system and blocking raycast.

Hi, Rodiaz89.

Did you manage to solve this? I am trying to do exactly the same, but no luck so far…

Never got a “Perfect” solution for this, it was either modify the git repository which I think it’s way too much work for something like that or like mentioned above use other libraries that connect with it. For my situation I just decided to use the regular Input class and do some platform compilation dependencies, I’m sure there is something that can be done but I decided for a simple solution for now.

1 Like