Search Unity

Question Accurate hit detection on custom mesh UI?

Discussion in 'UGUI & TextMesh Pro' started by andyz, Jan 19, 2024.

  1. andyz

    andyz

    Joined:
    Jan 5, 2010
    Posts:
    2,268
    UGUI makes it quite easy to add or generate mesh elements in your UI, as done in UI Extensions for example.
    However there seems to be no collision mechanism to handle non-rectangular shapes, is this so?

    It seems to be a weakness of the UI, but there are various hacks around as you can override Graphic.IsRaycastLocationValid. I used a PolygonCollider2D and shared the vertices passed to Graphic.OnPopulateMesh ! It seems an odd way to do it yet works if you sort out the Rect Transform to fit