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. Dismiss Notice

New Input System - Listen To All Buttons And Find Out Which

Discussion in 'Input System' started by BitBenderGames, Dec 20, 2020.

  1. BitBenderGames

    BitBenderGames

    Joined:
    Aug 9, 2015
    Posts:
    71
    Hello,

    Using the new input system, how can I listen to any button press and then find out which button it was that was pressed?
     
  2. Holonet

    Holonet

    Joined:
    Aug 14, 2017
    Posts:
    84
    This is in the documentation here: How do I…? | Input System | 1.0.1 (unity3d.com)
    A bit less than halfway down, there's code for listening for any button:
    Code (CSharp):
    1.   var myAction = new InputAction(binding: "/*/<button>");
    2.     myAction.onPerformed += (action, control) => Debug.Log($"Button {control.name} pressed!");
    3.     myAction.Enable();
    They warn it's not performant, naturally, since you're constantly grabbing every button anywhere.
     
    agamiof likes this.
  3. mp3magnat

    mp3magnat

    Joined:
    Aug 2, 2020
    Posts:
    3
    Thanks, dude, you helped me a lot.
     
    Holonet likes this.