Search Unity

Screen Space Overlay Issue

Discussion in 'UGUI & TextMesh Pro' started by GeneralDollar, Oct 21, 2018.

  1. GeneralDollar

    GeneralDollar

    Joined:
    Mar 24, 2018
    Posts:
    27
    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!
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    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).
     
    GeneralDollar likes this.