New Input System - How to Read Mouse Position Continuously ?

Hello,
I’m using new Input System.
With this new Input System, I can make game read value of mouse position.
The problem is, it only read when mouse is moved. If the mouse is idle, Input System won’t invoke my mouse callback so my code to read mouse position won’t start.

public void OnAim(InputAction.CallbackContext context)
{
    mousePosition = mainCamera.ScreenToWorldPoint(context.ReadValue<Vector2>());

while mouse focus on game screen :
context.started always false
context.performed always true
context.cancelled always false

How to read mouse position while my mouse is stop moving using new Input System?

Solution A:

Vector2 mousePosition;

void OnAim(InputAction.CallbackContext context)
{
    mousePosition = context.ReadValue<Vector2>();
}

void Update()
{
    var projectedMousePosition = mainCamera.ScreenToWorldPoint(mouseMosition);

Solution B:

void Update()
{
    var mousePosition = playerInput.actions["aim"].ReadValue<Vector2>();
    var projectedMousePosition = mainCamera.ScreenToWorldPoint(mousePosition);
10 Likes

Thank you for your answer.