Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by rjth · Oct 19, 2016 at 10:35 PM · uiguiraycastcanvas

How to physics raycast through overlay UI?

I have a transparent image full screen inside an overlay canvas. The transparent image only turns visible on horizontal swipes (pagination style). I would like to interact with my world space 3D objects with mouse input, but the overlay canvas is blocking my raycast. Are there any methods to pass through the overlay canvas image?

RayscastAll returns 0 if the raycast target of the image is set to true. I have to have it true, because I am detecting the swipe gesture on it.

Thank you.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by doublemax · Oct 19, 2016 at 10:47 PM

Put the overlay on a dedicated layer and ignore that layer in the RayCast call (layerMask parameter).

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image rjth · Oct 19, 2016 at 10:55 PM 0
Share

I have tried it, but doesn't seem to work. I've created a new Layer on the number 11 slot.

 if(Physics.Raycast(ray, out hit, 100.0f, 11)) {}

This is how the raycast looks now.

avatar image doublemax rjth · Oct 19, 2016 at 10:57 PM 1
Share

The RayCast call expects a Layer$$anonymous$$ask, not a LayerNumber.

Corrected code:

 Layer$$anonymous$$ask mask = Physics.DefaultRaycastLayers & ~ (1 << 11);
 // alternatively:
 Layer$$anonymous$$ask mask = Physics.DefaultRaycastLayers & ~Layer$$anonymous$$ask.Get$$anonymous$$ask("layername");

 if(Physics.Raycast(ray, out hit, 100.0f, mask)) {}

avatar image rjth doublemax · Oct 19, 2016 at 11:30 PM 0
Share

I have put my Tooltip (3D object) layer on the 8th position and the overlay canvas elements to the 9th position. $$anonymous$$y code now looks the following:

 if(Physics.Raycast(rayOrigin, out hitInfo, 100.0f, 1 << 8)) {}

But unfortunately it still doesn't work. Any idea what could be the issue?

Show more comments
avatar image rjth · Oct 19, 2016 at 10:57 PM 0
Share

However the RayCastAll now returns both the object I want to hit and the overlay canvas. I can take now the [1] from the hits array, so I can make it work. I still wonder why doesn't it work with the simple Raycast.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

141 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Text in UI disappears when clicked on 0 Answers

How to forbid float sizes and positions of all UI elements of UGUI while editing? 1 Answer

GUI buttons within an augmented GameObject AR Foundation 0 Answers

OnPointerEnter blocked by something 2 Answers

Problem with creating button via script. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges