Unity-Technologies / XR-Interaction-Toolkit-Examples

This repository contains various examples to use with the XR Interaction Toolkit
Other
1.12k stars 363 forks source link

[AR] Gui doesn't block Raycasts #14

Open d4n3x opened 4 years ago

d4n3x commented 4 years ago

This happens while in AR mode and a Plane is already detected. If the Screen is overlayed with a GUI, the CUI doesn't block the raycast and so on Button-Press an Object is placed.

Unity-Version: 2019.3.0f3 with XR Interaction Toolkit

unnanego commented 4 years ago

I can't be certain, but I have this problem since 2019.1. The workaround is to only get the first touch event and block all others - there's a bug in Unity and it lets some of checks through (only on iOS), maybe this is it? Try checking only at the first firing of touch event and block the check until the finger is lifted.

StephenHodgson commented 4 years ago

Isn't uGUI deprecated anyway?

Any luck with UIElements?

d4n3x commented 4 years ago

@StephenHodgson The problem occurs with the UIElements (Buttons, Sliders, etc.) also. If that is a thing what @unnanego mentioned, then this seems to be a workaround. But I honestly never had that problem before.

So maybe there is a chance that it is an issue of the XR Interaction Package?

d4n3x commented 4 years ago

I tried to figure it out and tried to check in the TapGesture.CanStart() if i can check if the Pointer is over an UIElement. Surprisingly the data i get is always off by one. Means if I click the UI 3 times, on the first a Object is placed then it works fine. If i click 3 times on the trackable Plane and clicked on the UI before that then the object is placed on the 2nd and 3rd click. Is anyone experienced with that problem?

d4n3x commented 4 years ago

Allright I have a Fix/Workaround for that finally:

For all gestures you want to Block when the Pointer is on the GUI u have to add following lines at the start of the method CanStart():

if(EventSystem.current.IsPointerOverGameObject(FingerId)) return false;

If there are more Fingers for this Gestures you have to check for both IDs. Tested and working for me.

JeffRuddick commented 4 years ago

I'm still having difficulty with this issue. You are placing this code on the ARPlacementInteractable script?

d4n3x commented 4 years ago

Yes as far as i remember - if u still have problems i can look in my code tomorrow :-)

JeffRuddick commented 4 years ago

If you don't mind checking...I would greatly appreciate it!

d4n3x commented 4 years ago

If you don't mind checking...I would greatly appreciate it!

Alright @JeffRuddick - First u have to copy the preview Package in your Project to be able to edit the scripts. I am working with preview version 0.9.3 and as I edited the Package code to fix this - I am not longer able to upgrade to a newer Package version. So u have following Scripts that needs the fix: DragGesture.cs, PinchGesture.cs, TapGesture.cs, TwistGesture.cs;

In each of this four scripts you add the "using UnityEngine.EventSystems" and then search for the "CanStart()"-Method.

In each of this methods u have to add only one of the following lines at the start of the function regarding its a one-finger or a two-finger interaction script:


if(EventSystem.current.IsPointerOverGameObject(FingerId1) || EventSystem.current.IsPointerOverGameObject(FingerId2)) return false;


if(EventSystem.current.IsPointerOverGameObject(FingerId1)) return false;


This should fix ur problems. But let me know if it works finally ;-)

JeffRuddick commented 4 years ago

@d4n3x Wow....finally got it working! Thanks for the help.

idrisbrewster commented 4 years ago

If you don't mind checking...I would greatly appreciate it!

Alright @JeffRuddick - First u have to copy the preview Package in your Project to be able to edit the scripts. I am working with preview version 0.9.3 and as I edited the Package code to fix this - I am not longer able to upgrade to a newer Package version. So u have following Scripts that needs the fix: DragGesture.cs, PinchGesture.cs, TapGesture.cs, TwistGesture.cs;

In each of this four scripts you add the "using UnityEngine.EventSystems" and then search for the "CanStart()"-Method.

In each of this methods u have to add only one of the following lines at the start of the function regarding its a one-finger or a two-finger interaction script:

if(EventSystem.current.IsPointerOverGameObject(FingerId1) || EventSystem.current.IsPointerOverGameObject(FingerId2)) return false;

if(EventSystem.current.IsPointerOverGameObject(FingerId1)) return false;

This should fix ur problems. But let me know if it works finally ;-)

This doesn't seem to be working for me, can you potentially post your code here? I have taken all of these steps and it still will place objects on the plane when I click UI buttons

JeffRuddick commented 4 years ago

@idrisbrewster Make sure that you copy the preview package into your project. This was quite tricky for me and caused a few issues (make sure you back up). You might want to check out the YouTube Video below posted by Dilmerv. It goes through the process in detail. The modifications above worked for me after copying the preview package and making the necessary adjustments. Hope this helps.

https://www.youtube.com/watch?v=UvLROt_wnus&list=PLQMQNmwN3Fvx2d7uNxMkVOs1aUV-vxrlf&index=14&t=0s

elvis75k commented 2 years ago

Tried the recent 2.0.0 release but the ui still doesn't block Raycast - Scenes\ARInteraction_MultipleObjects is there anything EASY I can do to fix?

tichise commented 2 years ago

I too am looking for a permanent solution on this issue.

Creepymulder commented 1 year ago

Same !