Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Resolved Delta [Mouse] is triggering InputActionPhase.Started and Canceled constantly?

Discussion in 'Input System' started by LandHT, Aug 15, 2020.

  1. LandHT


    Feb 3, 2017
    Setup (UnityEvents):


    Code (CSharp):
    1.  public void OnRotationInputBegan (CallbackContext _context)
    2.     {
    3.         Vector2 _rotationInput = _context.action.ReadValue<Vector2> ();
    4.         switch (_context.phase)
    5.         {
    6.             case InputActionPhase.Started:
    7.                 Debug.Log ("Started");
    8.             break;
    9.             case InputActionPhase.Canceled:
    10.                 Debug.Log ("Canceled");
    11.             break;
    12.         }
    13.     }
    With ActionType being a Button (WASD, Run Button, Jump Button) there's no issue, InputActionPhase.Started triggers at key press and InputActionPhase.Canceled at release, 1 time only.

    But when the ActionType is a value (Vector2 _rotationInput) Started and Canceled are being triggered continuosly each frame while the value is changing. It is not behaving as a "start" and an "end" like key presses.

    What's going on?
  2. Rene-Damm


    Unity Technologies

    Sep 15, 2012
    This is an artifact of how the delta controls operate. Deltas are somewhat "special" in that they accumulate within frames and then reset at the beginning of the next frame. So, say you have two mouse motions in the first frame and then another in the next frame. You'll get

    Code (CSharp):
    1. Frame 1:
    2.   (deltaX1, deltaY1)
    3.   (deltaX2+deltaX1, deltaY2+deltaY1)
    4. Frame 2:
    5.   (0, 0)
    6.   (deltaX3, deltaY3)
    7. Frame 3:
    8.   (0, 0)
    Thus the unusual pattern of how the actions fire.
    LandHT likes this.