I’m working with a large project that contains both the standard input system and the new input system, and I’m slowly migrating the old implementations to the new one.
I’ve read online how Mouse.current.leftButton.wasPressedThisFrame
is often used instead of Input.GetMouseButtonDown(0)
, but I always got the impression that the new action-based system aimed at doing away with input polling from inside an Update()
. Which is why I tried adding an “Left Click” action to my Input Actions and subscribed to the .performed
event in my code to detect mouse clicks.
At first glance both produce the same results… except in one specific case where I need to call EventSystem.current.IsPointerOverGameObject()
when the mouse is clicked. For some reason, Unity cannot call this from within an action callback, and spits out this warning:
Calling IsPointerOverGameObject() from within event processing (such as from InputAction callbacks)
will not work as expected; it will query UI state from the last frame.
This breaks the previous functionality, as IsPointerOverGameObject()
now seems to always return true
.
My question is: what is the default usage of Mouse.current.*
(or Pointer.current.*
) that Unity expects us to implement with the new Input System? Is it a permanent stand-in replacement for the old Input.GetMouseButtonDown(0)
? Should I try to handle as many inputs as possible with event callbacks, and only use Mouse.current.*
in those edgecases where callbacks are not available?
Of course, I could have a mouse-click callback that toggles a local bool wasMouseClickedThisFrame
, and then read its value in my Update()
, but that hardly seems better than straight up calling Mouse.current.leftButton.wasPressedThisFrame
where needed.