Jump to content

Raycast is not blocked by objects / ui


Recommended Posts

Now when I interact with the ui I accidentally click on the object behind the ui, I have a script added to the object so that when I select it with a raycast I can paint it. So when I click on the ui I select the ui and the object behind and both scripts are triggered..

Edited by bella-1995
Link to comment
Share on other sites

@chengnay I use Vive Input Utility example scen (ugui scen) this scen have all scripts what i use. I just add Debug.Log(raycastResult). And debug log shows me that raycast hitting all object in scen(You can see the result in example.zip which I added at the top). Both cubes have a box collider. Canvas have a canvas target. Nothing has been added to the scene except a couple of cubes and a debug log. if you really need the sources, I'll try to get them.

Link to comment
Share on other sites

@bella-1995 Like you said, the raycastResult will list all objects that it hits. VIU will return the first one(nearest to you) when your raycast hits.

We test on UGUI scene with a cube in front of the button, but we didn't see the button was pressed when I pull the trigger button.

From the gif image you attached, the button didn't even being hovered when you hit it through the cube.

Could you try again or provide the source for further investigation? thanks!

Link to comment
Share on other sites

Hi @bella-1995,

I'm guessing you get "raycastResults" from ViveRaycaster.SortedRaycastResults ?

That means this property stores all raycast results and sorted by hit distance, hence index 0 result is the nearest.

(Or just use ViveRaycaster.FirstRaycastResult() function)

Default UGUI event, reticle and guideline all interact with only the first raycast result, you can do the same.


Alternatively you can also implement your interaction logic within the event handlers.

FYR., more details from Unity docs:


Link to comment
Share on other sites

sorry, but maybe here i have a problem? (56-118) it's my custom code. 60 - 97 i check to press trigger on controller (if pressed i add a gameobject to gameobject list where i save all gameobject which i select from raycast). If this code without problem i will try to get clear project only with problem..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...