Search Unity

Bug eventData.hovered returns nothing when Right Clicking

Discussion in 'Scripting' started by RadRedPanda, Oct 30, 2021.

  1. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,647
    So I've been experimenting with an inventory system where you can move stuff around, similar to Minecraft or Terraria. One thing I ran into was that when I use the
    OnPointerClick
    event, I can check how many Canvas objects I'm hovering into by using the
    eventData.hovered
    , to return me a List of objects under the mouse. One problem I ran into though, is that when I use Right Click, the List is null. Is there any explanation for this?

    Here's the code I was using, incase it wasn't clear.

    Code (CSharp):
    1.     public void OnPointerClick(PointerEventData eventData)
    2.     {
    3.         // prints which button was clicked and how many in list
    4.         Debug.Log(eventData.button + " " + eventData.hovered.Count);
    5.  
    6.         foreach (GameObject o in eventData.hovered)
    7.             Debug.Log(o.transform.name);
    8.         // returns all of the objects fine when Left Clicking
    9.         // returns an empty list when Right Clicking though
    10.     }
    You can see here in the output that on Left click, it returns 4 objects as expected, however when right clicking in the same spot, it returns 0.
    upload_2021-10-30_17-56-4.png

    The documentation on this event is pretty barebones, does anyone have insight about this?