Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

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

  1. LandHT

    LandHT

    Joined:
    Feb 3, 2017
    Posts:
    84
    Setup (UnityEvents):

    upload_2020-8-15_11-53-58.png

    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.     }
    14.  
    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

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    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.