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?

UPDATE: Currently the correct way to do this is to uncheck the “Raycast target” field on your Image/Raw Image/Text/etc component. :slight_smile: 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 :slight_smile:

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.

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!

60365-captura-unity.jpg

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. :slight_smile:

115069-imagepropertiesmod.jpg