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 does the Player Input Component trigger three times?

Discussion in 'Input System' started by Zephus, Sep 7, 2020.

  1. Zephus

    Zephus

    Joined:
    May 25, 2015
    Posts:
    354
    I've set up a very basic example where the "Fire" action from the example prints a message. "One" is subscribed to the performed-Event and "Two" is connected through the Player Input Component:

    upload_2020-9-7_19-6-5.png

    Shouldn't these be exactly the same? Why is "Two" printed twice when I press the button and a third time when I release it, but "One" only prints once when I press the button down?

    upload_2020-9-7_19-5-43.png



    Code (CSharp):
    1. Inputexample actions;
    2.  
    3. private void OnEnable()
    4. {
    5.     actions = new Inputexample();
    6.     actions.Enable();
    7.  
    8.     actions.Player.Fire.performed += One;
    9. }
    10.  
    11. public void One(InputAction.CallbackContext context)
    12. {
    13.     Debug.Log("One");
    14. }
    15.  
    16. public void Two(InputAction.CallbackContext context)
    17. {
    18.     Debug.Log("Two");
    19. }
     
  2. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,269
    Check the context phase. It might be performing "started" "performed" and "cancel"
     
    Zephus likes this.