Screen Space Overlay Issue

I have a canvas set to screen space overlay with some UI elements that I would like to be able to interact with. These elements have colliders on them to detect the raycast hits.

My issue is that when I build the project, I cannot interact with the UI elements. However, when I change the Screen Space to Camera, the project works completely fine and I can click and interact with my UI elements. I was hoping someone might be able to shed some light on what I might be doing wrong.

Thanks!

When working with UI you don’t need colliders. UI elements have Rect Transforms which define the “Bounding Box” of the elements.
Use RectTransformUtility.RectangleContainsScreenPoint to check if a point is inside the given rectangle.

If you want to do more detailed raycast checks you can use use the method IsRaycastLocationValid on an component implementing ICanvasRaycastFilter (like Image – or you can write your own).

1 Like