how do you retrieve the clicked collider in eventData

I use the event system exclusively but need to retrieve the collider that was clicked on, like RaycastInfo.collider

I see EventSystems.RaycastResult has worldPosition, normal but no information on the rigidbody or collider hit, is there a workaround?

NOTE: I use this but would rather not go through the camera and raycast from it.

var clickPosition = eventData.pointerCurrentRaycast.worldPosition;
RaycastHit raycastHit;
Physics.Raycast (Camera.main.ScreenPointToRay (eventData.position), out raycastHit);
Interaction.SetLockAttack (raycastHit.collider, eventData.pointerCurrentRaycast.worldPosition, GetComponent<Stats> ());

What’s wrong with RaycastResult.gameObject?

Since a EventSystem.Raycast can’t hit any number of things, there is not any more specific type it can return.

1 Like

I’m wrecking some old code that was relying on passing collider as parameter, attachedRigid was being used to grab the top component, rough. Don’t really want to wreck more than necessary so I’ll stick with the raycast hack for now but next project I’ll use .gameObject, thanks.

.gameObject.GetComponent()

?

no that would have to be gameobject.collider.attachedrigidbody, the point is it’d have to be changed in tons of spaghetti code that’s already breaking at the seams (I’m trying not to listen to that little voice that says “burn it all and redo everything”)