Search Unity

Feedback InputAction as a reference?

Discussion in 'Input System' started by KingKRoecks, Jun 17, 2021.

  1. KingKRoecks

    KingKRoecks

    Joined:
    Jul 28, 2013
    Posts:
    155
    I'm trying to create listeners for InputActions in a programmatic way.

    I want to be able to designate a "Fire" action and then refer to it in code. In a local splitscreen game, I can't listen globally, because I have to listen to interactions on the specific PlayerInput.
    If I add a listener to the PlayerInput, I can either add the listener to every event on every action or I can add a single method that takes the CallbackContext.

    Code (CSharp):
    1. playerInput.currentActionMap.actionTriggered += (callback) => {};
    This lets me get events for every single InputAction on the map. But when I get an event triggered, I want to be able to compare it to determine that "Fire" was pressed as opposed to another input.

    Is there any way to accomplish this other than string comparison?
     
  2. KingKRoecks

    KingKRoecks

    Joined:
    Jul 28, 2013
    Posts:
    155
    Assuming I define the InputAction in a way I can refer to

    Code (CSharp):
    1. public class InputActionWrapper {
    2.     public InputAction action;
    3. }
    I could potentially refer to the action I add to the PlayerInput, but there doesn't appear to be a way to AddAction with a reference to an InputAction.

    So I'm struggling to find a way to tie into this.

    Anyone have any ideas?
     
  3. KingKRoecks

    KingKRoecks

    Joined:
    Jul 28, 2013
    Posts:
    155
    Novack likes this.