Search Unity

RaycastAll... Is not Raycasting all...?

Discussion in 'UGUI & TextMesh Pro' started by Avalin, Jul 9, 2021.

  1. Avalin

    Avalin

    Joined:
    Oct 12, 2018
    Posts:
    98
    Code (CSharp):
    1.         private static List<RaycastResult> GetUIElementsAtPosition(Vector3 position)
    2.         {
    3.             var eventSystem = RewiredEventSystem.current;
    4.             var pointerEventData = new PointerEventData(eventSystem) { position = position };
    5.             var results = new List<RaycastResult>();
    6.             eventSystem.RaycastAll(pointerEventData, results);
    7.  
    8.             return results;
    9.         }
    This be my code. I have several layered UI elements (images) on top of one another, but only 1 UI element is ever present in the results list, the one closest to the camera.

    I run this method in Update, with the position "ReInput.controllers.Mouse.screenPosition;" (I'm using Rewired)
    And I want to retrieve every single UI element I am hovering over.

    Am I missing something?
     
  2. Avalin

    Avalin

    Joined:
    Oct 12, 2018
    Posts:
    98
    Eh, I separated this piece of code into another project and it works completely fine there, I'm getting all objects.
    I used a home-made logging function that did not print out all elements in the list, and that was in fact the issue. :oops: