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.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Why do some 'performed' callbacks seem to be called twice (or zero times) per frame?

Discussion in 'Input System' started by Rs, Jun 16, 2021.

  1. Rs

    Rs

    Joined:
    Aug 14, 2012
    Posts:
    74
    Hello,
    As per title my question is why, in the particular case of a Pass Through / Vector2 value (given by Pointer or Mouse bindings), does the performed callback seem to be called twice per frame?
    I put together a simple test case.
    In the zip file you'll find
    1. MainControls.inputactions
    2. MainControls.cs
    3. InputTestCase.cs
    Import in your asset and attach InputTestCase to anything.
    The key code lines are the following:

    Code (CSharp):
    1.  
    2. controls.Gameplay.Aim.performed += (x) => { aimPerformedCount++; };
    3.  
    increment aimPerformedCount every time it's called

    Code (CSharp):
    1.  
    2. Debug.LogFormat("Aim: {0} ; Fire1: {1} ; Fire2: {2}", aimPerformedCount, firePrimPerformedCount, fireSecPerformedCount);
    3. aimPerformedCount = 0;
    4.  
    at the end of the Update, print out the counter and and set it to 0

    The output is always either 0 or 2. So my question can be reduced to why is it not 1?

    I'm testing this in Unity 2019.4.6 with Input System 1.0.2. I know it's not up to date but I have faith in those LTS letters attached to the version. And it'd be good to know if it behaves similarly with later versions, if anyone is up for testing.
     

    Attached Files:

    Last edited: Jun 16, 2021
  2. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    I have it either 0 or 1, what is printed in input debugger when you play mode? It could be that you get pointer bound two times, or it could be that you run in fixed update or something similar.
     
    Rs likes this.
  3. Rs

    Rs

    Joined:
    Aug 14, 2012
    Posts:
    74
    Answering my own question: the sole, simple reason is that I have 2 bindings configured for the Aim action. Pointer counts as Mouse I think. After removing the Pointer binding the output is either 0 or 1.