Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

GraphicRaycaster not detecting drop down despite "UI" tag?

Discussion in 'UGUI & TextMesh Pro' started by SFvdB, Nov 13, 2021.

  1. SFvdB

    SFvdB

    Joined:
    Mar 10, 2014
    Posts:
    27
    I must be doing something wrong, here but I can't see where. I am building a game with the new Unity Input System and am having a hard time getting the GraphicRaycaster to recognise the UI elements. I've had to use this code to detect the elements, as using anything similar to "Eventsystem.current.IsPointerOverGameObject" doesn't work at all.

    I've found snippets like this twice now, and it works, up to a point.

    Code (CSharp):
    1.        var pointerEventData = new PointerEventData(EventSystem.current) { position = mousePos };
    2.         List<RaycastResult> results = new List<RaycastResult>();
    3.         graphicRaycaster.Raycast(pointerEventData, results);
    4.      
    5.         foreach (var result in results)
    6.         {
    7.             if (result.gameObject.CompareTag("UI"))
    8.             {
    9.                 Debug.Log("POINTER IS OVER UI!");
    10.                 _isOverUI = true;
    11.                 return true;
    12.             }
    13.         }
    However, with the TMP dropdownbox's drop down, the viewport that's extended isn't detected as UI, despite the object (its parent and any children) having the UI tag. What's up? Why is this happening? Is this due to it extending beyond its parent panel, perhaps? It is set to be Raycast Target... Here's my situation:

    Screenshot 2021-11-13 at 21.53.19.png

    The red part is safely ignored by the OverUI check. The bottom two panels in the green box (the white and transparent white) are detected properly. But the orange box - despite it and its children being set to the tag "UI" is not detected as such. How can I fix this?
     
  2. SFvdB

    SFvdB

    Joined:
    Mar 10, 2014
    Posts:
    27
    Apparently the drop down box has its own canvas with its own GraphicsRaycaster. I have not yet found a solution on how to fix this considering how I reference another graphicRaycaster in the code...