[Unity] Game Objects behind the Canvas UI are not receiving click events

This article can be read in about 2 minutes.
PR

The purpose

In Unity development, UI elements on the Canvas system can intercept input events (like clicks) that are intended for the GameObjects underneath them, making those GameObjects unclickable (This is especially frustrating for users when the UI is semi-transparent). This article presents the standard solution for this problem.

PR

Solution

By changing the UI settings, you can make the event pass through to the object below it, ignoring the event on the current UI element. This setting can be changed from either the UI or the code.

from UI

By unchecking the Raycast Target property on the corresponding UI Image component, the UI will ignore mouse events.

PR

from code

Setting Image.raycastTarget to false causes the UI to ignore mouse events.

Below is an example of setting raycastTarget to false in a script attached to the target UI element.

GetComponent<Image>().raycastTarget = false;

comment

Copied title and URL