Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
avatar image
3
Question by Matheuz · Oct 20, 2015 at 05:05 PM · uiraycastbuttonimage

UI Image not blocking raycast

I just upgraded to Unity 5.2.1p4 and I am having some issues with the UI.

My parent object has an image, a button and its child object has an image. When I click on the child object, it doesn't block the Raycast and the parent button (behind it) gets the click. I thought Images are supposed to block Raycasts. I even tried using a Canvas Group and setting its "Block Raycasts" to true, with no success.

The only way I found to prevent the raycast propagation was adding an empty, non-interactable button to the child object, which I think is too much.

Am I missing something or did something change on the last updates?

EDIT: There is an example project (about 30Kb): http://www48.zippyshare.com/v/noIQmtnX/file.html Clicking on the black square triggers the white button. The only way to make the black square blocking the raycast is by adding an empty button to it.

Comment
Add comment · Show 8
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 meat5000 ♦ · Oct 20, 2015 at 08:04 PM 0
Share

http://docs.unity3d.com/$$anonymous$$anual/script-GraphicRaycaster.html

avatar image Matheuz meat5000 ♦ · Oct 20, 2015 at 08:11 PM 0
Share

That doesn't help me at all. I've been using the same Graphics Raycaster in this project, and by blocking mask is set to "Everything". The problem is that my image will only block a raycast if it has a button attached to it, otherwise, its parent will receive the raycast. Shouldn't an image block raycasts regardless of it has a button or not?

avatar image Cherno Matheuz · Oct 20, 2015 at 10:13 PM 0
Share

Yes, it should Try giving it a Canvas Group and test the value combinations.

Show more comments
avatar image digzou · Oct 21, 2015 at 07:44 AM 0
Share

Does any of your child objects have scroll rect? Even I was facing similar issues and ended up doing what you did.

avatar image Matheuz digzou · Oct 21, 2015 at 03:58 PM 0
Share

Not really, its only child is the image. I uploaded an example project (about 30$$anonymous$$b) and the link is on the description. Thanks for the help.

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by meat5000 · Oct 21, 2015 at 04:20 PM

Looking at your project it appears that by default UI elements are non-interactable. This is why a button appears to fool it.

Try adding "UI->Selectable" to your Child object and setting it to not react on click. This makes it block just fine.

EDIT: It seems there are multiple things that should perform this task and many things that suggest that what you observe is default behaviour.

Take this for example:

http://docs.unity3d.com/ScriptReference/ICanvasRaycastFilter.html

and this

http://docs.unity3d.com/ScriptReference/UI.MaskableGraphic.html

Both of which suggest that blocking a raycast is a scripted affair.

Comment
Add comment · Show 15 · 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 Matheuz · Oct 21, 2015 at 04:53 PM 0
Share

I posted a comment here about 20 $$anonymous$$utes ago but apparently it was moved to moderation. By myself?

"$$anonymous$$atheuz moved the comment "UI Image not blocking raycast" to moderation".

avatar image meat5000 ♦ Matheuz · Oct 21, 2015 at 05:31 PM 1
Share

Lol you are experiencing a Site bug at the moment. Ill fish it out.

avatar image Matheuz · Oct 21, 2015 at 05:15 PM 0
Share

Happened again, I give up about UA. Going to the forums: http://forum.unity3d.com/threads/5-2-1p4-image-not-blocking-click.362650/

avatar image npatch Matheuz · Oct 21, 2015 at 05:34 PM 1
Share

Selectable works but it seems to me to be a bug. This shouldn't work like this. If you unparent the child image...as it is...just unparent it and make sure the child image is below the parent image(As you add children UI elements to the same depth under a parent, the latter will be rendered last,so if the child image is listed after the parent image then it's rendered last), it works without CanvasGroups and without anything else.Just the images and the button. In fact in that kind of hierarchy no matter if Raycast Target is checked or unchecked, the button is hidden. The problem is with the parenting. Somehow this affects things. Unless I'm missing sth or have misunderstood sth in the documentation this feels like a bug in the engine.

There's another roundabout way of doing this, create a different canvas with a different sort order for the layer or plane distance depending on the type of canvas you want. Depends on what you want to do with the image on top of the button.

avatar image Matheuz npatch · Oct 21, 2015 at 05:40 PM 0
Share

I'm glad I'm not the only one that thinks it's a bug. The button workaround does it by now, but I was just wondering if they noticed this yet. They just released 5.2.2 but I'm not sure if it fixes it, since I didn't see anything on the release notes that wasn't on p4. Thanks for the help, I'll wait and see.

Show more comments
avatar image Matheuz · Oct 21, 2015 at 05:32 PM 0
Share

Well, UIButtons are UISelectables (source), so it's not that different. $$anonymous$$y question is: shouldn't images block raycasts regardless of it has a Button (or Selectable) or not?

I mean, isn't it what all of these are about?

http://answers.unity3d.com/questions/830371/ui-46-image-blocks-mouse-click.html

http://answers.unity3d.com/questions/816861/46-ui-image-is-capturing-clicks-how-to-prevent.html

http://answers.unity3d.com/questions/822273/how-to-prevent-raycast-when-clicking-46-ui.html

avatar image meat5000 ♦ Matheuz · Oct 21, 2015 at 05:59 PM 0
Share

I added a link to my answer. Its very curious.

Note that your black image has no texture in it.

avatar image npatch meat5000 ♦ · Oct 21, 2015 at 06:02 PM 0
Share

It is curious indeed. But then why does it work when the same Image with no sprite is unparented and placed in a higher child index? It's the same thing just not parented.

By that logic, the event should have fallen back to the button ins$$anonymous$$d of being blocked.

Show more comments
Show more comments
avatar image Matheuz · Oct 21, 2015 at 06:03 PM 0
Share

I set a sprite (default UISprite) to both of my images and the alpha is 100%. Still happens.

avatar image meat5000 ♦ Matheuz · Oct 21, 2015 at 06:39 PM -1
Share

Yeah that value seems useless :D Ah well sorry, I tried.

I found a few more things in the docs that could give some insight.

avatar image
1

Answer by npatch · Oct 21, 2015 at 12:01 PM

If I'm not mistaken, There's a Raycast Target checkbox in Image. Try unchecking that box in the parent Image to avoid blocking the raycasts, since that one is probably first to get raycasted as you navigate to the children in the view.

Comment
Add comment · Show 2 · 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 Matheuz · Oct 21, 2015 at 03:48 PM 0
Share

Thanks for the suggestion, but it didn't work at all. I will try to post an example project here.

avatar image Matheuz · Oct 21, 2015 at 03:56 PM 0
Share

Here is the example project (about 30$$anonymous$$b): http://www48.zippyshare.com/upload Clicking on the black square triggers the white button. The only way to make the black square blocking the raycast is by adding an empty button to it.

avatar image
0

Answer by IsouEU · Mar 09 at 09:02 PM

and if the problem occurs in a button ? I have a click walk script and it is stupidly activated every time a UI button is clicked, the only way I found was to deactivate and activate the script, inside the button script.. which is stupid, the problem is that now I have a visual element (scoreboard with scroll) that does not have an on-click script, making it impossible for me to use my solution...

Comment
Add comment · 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

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

44 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

Related Questions

Scrollable Achievement Tabs? 1 Answer

UI image with button component not tracking mouse correctly 1 Answer

Detect only UI button click 3 Answers

I Have a Button in Canvas, i Click anywhere except the button and it gets clicked 0 Answers

UI Enabled not working? 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