I have a card which has some icons on it. The card has an IPointerEnterHandler on it and it works fine and is called when the mouse enters the object. The card has a hidden button that covers the surface.
The problem is, there are some nested GameObjects that I want to detect IPointerEnterHandler events on. I have IPointerEnterHandler listeners on those objects, but they dont fire.
If I remove them from the card, they will fire when hovered. However, while on the card, they will not fire.
Here is a visual example, as well as the heirachy and the arrows correspond to the icons and their place in the hierarchy:
I tried using the EventSystem in an Update call on but the currentSelectedObject is always the Card (or rather the cards button which covers it).
private void Update()
{
Debug.Log(EventSystem.current.currentSelectedGameObject);
if (EventSystem.current.currentSelectedGameObject == gameObject)
{
Debug.Log(1);
}
}
Do you know how I can detect mouse over events on these nested objects (which have a UI element above them that is hogging the event)?. I'd like to avoid RayCasting if possible.
Temp Solution:
I've resorted to using a raycast for the time being. I put a collider on the small icon and I check if its hit while the mouse is over the card:
private void Update()
{
if (!_mouseIsOver)
{
HideActionOrPerk();
return;
}
// If it's already showing a card then dont bother checking to show again
if (_shownCardClone != null) return;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit[] hits = Physics.RaycastAll(ray, 100.0f);
Debug.Log(hits);
foreach(RaycastHit hit in hits)
{
S_ActionOrPerkIcon icon = hit.transform.GetComponent<S_ActionOrPerkIcon>();
if (icon != null)
{
ShowActionOrPerk(icon.tooltipCardGO);
}
}
}
I would have preferred the icon to handle this logic but this works for the time being. Better suggestions welcome.