Is EventSystems.EventSystem.IsPointerOverGameObject deprecated in Unity 2019.3?
Asked Answered
S

4

0

I am looking to detect if my cursor is on top of any UI elements (GameObject). I want to prevent running a function by checking if my cursor is on top of any UI Element.
The function looks like this:

   if (!pointerIsOnTopOfEvent) {
    return;
    } **// if the pointer here is on top of any UI element, stop doing the rest of the code**

    if (build_Manager.GetFarmObjectToBuild()== null)
    {
        return;
    }
    nodeRender.material.color = hoverColor;

I really appreciate it if someone has other methods if EventSystems.EventSystem.IsPointerOverGameObject is deprecated.

Selfexecuting answered 28/6, 2023 at 12:59 Comment(0)
P
0

me too, i need another solution to detect click on UI

Ploch answered 28/4, 2020 at 5:7 Comment(0)
L
0

If you don’t mind the new Input System it has an isPointerOverGameObject method.

Lithographer answered 8/6, 2020 at 19:56 Comment(2)

This looks like the deprecated method in question. Do you have a solution for 2019.3?

Manifold

I don't think is deprecated, it works on 2020.3 version. (Or maybe they decided to put it back.)

Amperehour
M
0

I have discovered that it is NOT deprecated, or at least not completely. In the documentation, you’ll notice UnityEngine.EventSystems is missing after 2019.1. Why this is, i don’t know.

However, you can still get at IsPointerOverGameObject by way of EventSystem.current.IsPointerOverGameObject(), and make sure you are using UnityEngine.EventSystem.

Manifold answered 6/6, 2023 at 2:37 Comment(0)
C
0

Try this

private bool IsPointerOverUIObject() {
        PointerEventData eventDataCurrentPosition = new PointerEventData(EventSystem.current);
        eventDataCurrentPosition.position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
        List<RaycastResult> results = new List<RaycastResult>();
        EventSystem.current.RaycastAll(eventDataCurrentPosition, results);
        return results.Count > 0;
}
Chalone answered 30/12, 2023 at 21:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.