Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
4
Question by AlwaysSunny · Oct 25, 2014 at 06:20 AM · uieventclick4.6

4.6 UI "image" is capturing clicks - how to prevent?

I've got a world-space UI system featuring menus with buttons, and I've just tried putting a new UI element with an image component at the "draw last" point in the canvas hierarchy (bottom of hierarchy) to act as a cursor.

Because it's right beneath the mouse, its presence seems to capture 90% of clicks and other mouse events, preventing my buttons from receiving click events. Obviously that's bad, but I'm not seeing an obvious way to disable an image's ability to capture clicks. No toggles on the component itself, IntelliSense didn't show anything promising. Putting the cursor image on the IgnoreRaycast layer didn't help.

Anyone else encountered this and have a nice solution?

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

3 Replies

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

Answer by CanisLupus · Nov 16, 2014 at 04:08 PM

UPDATE: Currently the correct way to do this is to uncheck the "Raycast target" field on your Image/Raw Image/Text/etc component. :) See the other answers, namely the first one mentioning this, by @Carlotes247 (and upvote them!).

OLDER WAYS, FOR REFERENCE:

If you want to disable input on your UI element, a clean solution is to place this script on it:

 using UnityEngine;
 
 public class GraphicIgnoreRaycast : MonoBehaviour, ICanvasRaycastFilter
 {
     public bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
     {
         return false;
     }
 }

ICanvasRaycastFilter lets you implement IsRaycastLocationValid, which is called by Unity whenever your mouse/touch is over the element area. If we always return false, it always says "nope, the cursor isn't over me" and the object will never block anything.

I hope this helps :)

Not related to your question: IsRaycastLocationValid can also be used for circle buttons, where the mouse can be over the rectangular area of the element but not yet inside the button graphic (which would be a circle). In such a case you would only return true if you calculated that screenPoint was inside the radius of the button, for example.

You can also add the Canvas Group component to your image object and uncheck "Blocks Raycasts" (and possibly Interactable). This will make the object behave like it's not there, click-wise.

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 AlwaysSunny · Nov 16, 2014 at 05:06 PM 0
Share

I recall finding a list of the UI event interfaces while investigating this - not sure how I missed that one! Big big thank-yous for providing this answer. :)

avatar image awplays49 · Nov 17, 2014 at 09:57 PM 0
Share

Hey Sunny, I'm aware this isn't the place, but I'm not sure how else to let you know, the black lines were caused by Unity grabbing a tiny bit of the tile above the grass, even though the editor said it didn't include any of the black. Can you report this information to Unity so that they now know how to fix it? It's not that it's not a known issue but they just don't know what causes it. I do now.

avatar image
5

Answer by Carlotes247 · Dec 21, 2015 at 02:58 AM

Hello! There is a way now in Unity 5 (I'm working on 5.3, don't know if before) where you can uncheck one field on the image component called "Raycast Target". This way, you don't need to add a new component!

alt text


captura-unity.jpg (21.2 kB)
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
avatar image
0

Answer by JennBren · Apr 15, 2018 at 04:01 PM

Greetings,

Just wanted to say, using Unity 2017.3 and by unclicking the "Raycast Target" box on the Image inspector still works great. There are a few updates of course to how it looks but this is still the correct method. Thank you so much for posting. :-)

alt text


imagepropertiesmod.jpg (27.5 kB)
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

30 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

Related Questions

UI - How can I prevent a Rect Transform on a canvas from blocking clicks? 1 Answer

4.6 UI OnBeginDrag event handler doesn't seem to work. 1 Answer

Raycast against UI in world space 4 Answers

How to wait click on button in my MessageBox analogue? 1 Answer

[4.6 - UI] How to call an event with button when the pointer is up the button image. 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