Equivalent to OnMouseOver in new EventSystem?

I’m rewriting some code to make use of Unitys EventSystem to get a more streamlined solution for both mouse and touch input.

I need to know if a pointer is stationary while being pressed but I can’t find an equivalent to OnMouseOver() in the EventSystem.

PointerEvents have the delta property and the IsPointerMoving() method but that is never false in OnDrag() since that is only called if the pointer has moved.

How could I get an event when IsPointerMoving() == false or delta == 0?

If I can’t, would it be possible to retrieve a list of all current pointers?
Then I could get the one with the correct pointerId and check its delta property.

Is the pointerId always the same as the Touch.fingerId of the same pointer/touch?

What would be a clean solution to do this?

You have the interfaces for pointer enter and exit. Redirecting to latest version of com.unity.ugui
If that’s what you are after.

No, I need to know if the pointer is stationary while something is being dragged, which happens after OnPointerEnter.

Just have an internal boolean “isPointerDown” that switches when OnPointerDown and OnPointerUp fire. Cache the Event’s/Input’s mouse position so that you can math out its mouseDelta. And process that in Update when isPointerDown is true.

If you simply want an OnMouseHover effect that fire every frame just do the same thing but instead of isPointerDown, OnPointerDown, and OnPointerUp; its “isPointerInside”, OnPointerEnter, and OnPointerExit.

The Eventsystem won’t fire events every frame if it doesn’t need to. but you can write your own IEventSystemHandler events and your own InputModule to do this.

1 Like

Well… I’ll point out that OnMouseOver does not contain data about the mouse being “stationary”, but that it’s just “over” the object.

In the case of the Unity EventSystem, it does not have the equivalent though. But instead you would use the ‘OnPointEnter’ to register enter, and ‘OnPointerExit’, to register leave. And the time in between that is “over”.

public class SomeScript : MonoBehaviour, IPointerExitHandler, IPointerEnterHandler
{

    private bool _over;
 
    void Update()
    {
        if(_over) this.OnPointerOver();
    }
 
    void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
    {
        _over = true;
    }

    void IPointerExitHandler.OnPointerExit(PointerEventData eventData)
    {
        _over = false;
    }
 
    private void OnPointerOver()
    {
        //do stuff
    }

}

Something like this.

Then as for the trapping motion. During OnPointOver, just track the pointer position. And see if there was a change since last frame.

I don’t know how your original design was tracking this with OnMouseOver… but basically do that. Since this code here emulates the ‘over’ aspect of that functionality.