A way to reset MouseDelta or resolve a problem with it "charging" while mouse is disabled

Hi everyone! I made an input action which contains these action maps and actions:


I use it in my InputManager like this:

// property that has MouseDelta stored for other scripts to use
public Vector2 PlayerMouse { get; private set; }

...

// binding value to property
_inputActions.Player.Look.performed             += context => { if (Application.isFocused) PlayerMouse = context.ReadValue<Vector2>(); };
_inputActions.Player.Look.canceled              += context => { if (Application.isFocused) PlayerMouse = Vector2.zero; };

And this is how I rotate the player’s camera

private Transform _cameraTransform;
private float _lookSensitivity = 2;
private float _cameraRotAngle = 0;
private float _minCameraAngle = -75;
private float _maxCameraAngle = 75;

private void Update()
{
            _cameraRotAngle += -_input.PlayerMouse.y * _lookSensitivity;
            _cameraRotAngle = Mathf.Clamp(_cameraRotAngle, _minCameraAngle, _maxCameraAngle);
            _cameraTransform.localEulerAngles = new Vector3(_cameraRotAngle, 0, 0);
            transform.Rotate(new Vector3(0, _input.PlayerMouse.x * _lookSensitivity, 0));
}

Problem is, when I disable the ‘Player’ action map, move my pointer around, and then enable it, my mouse has some insane delta amount and my player starts rotating everywhere. Here’s the clip of it:

I’ve been thinking of resetting the delta value itself, when I reenable ‘Player’ action map, but I don’t think I can do that? Is there any way to solve this problem? Thanks!

Any luck with this? I have a similar problem. I want to enable mouse movement only after the application has “settled in” at startup.
At which point I get the accumulated mouse delta since application start :-/

Had the same problem. I set a bool in my input manager called isLocked. When disabling player inputs I also set it to true. After releasing the inputs I send vector2.zero instead of value from the context, effectively skipping the frame with big value change. This solved the issue for me. I hope this helps.

        internal void Lock()
        {
            gameInputs.Gameplay.SetCallbacks(null);
            isLocked = true;
        }

        internal void Release()
        {
            gameInputs.Gameplay.SetCallbacks(this);
        }


        public void OnLook(InputAction.CallbackContext context) 
        {
            if (context.phase == InputActionPhase.Performed) {
                if (isLocked)
                {
                    OnLookEvent(Vector2.zero);
                    isLocked = false;
                    return;
                }
                OnLookEvent(context.ReadValue<Vector2>());
            }
       }