Event System RaycastAll not detecting all raycastable ui elements at a position.
Im trying to create a ui panel that can be dragged around with a touch. I'm using the EventSystem raycastall to try and achieve this but im not getting all the ui elements that should be under the position being passed to the raycastall function.
I'm only getting three of the ui elements that are present in that area.
This is my code:
if (EventSystem.current.IsPointerOverGameObject(touch.fingerId))
{
PointerEventData pointer = new PointerEventData(EventSystem.current);
pointer.position = GetClampedTouchPosition(touch);
List<RaycastResult> raycastResults = new List<RaycastResult>();
EventSystem.current.RaycastAll(pointer, raycastResults);
if (raycastResults.Count > 0)
{
foreach(RaycastResult result in raycastResults)
{
Debug.Log("Objects hit by touch: " + result.gameObject.name);
if(result.gameObject.GetComponent<Button>() != null)
{
Debug.Log("Button found!");
}
}
}
Any help would be much appreciated.
Your answer
Follow this Question
Related Questions
EventSystem raycasting on World Canvas gameobject always returning worldPosition of zero 2 Answers
Is it possible draw linerenderer in a UI space? 0 Answers
Not correct ui scaling 0 Answers
The LWRP 6.9.1 PixelPerfectCamera breaks all my UI, normal PixelPerfectCamera works fine. Why? 0 Answers
Button with custom function working perfectly in unity editor but, not working in mac build ?? 0 Answers