Search Unity

How can I copy inputs from an action asset into a behaviour?

Discussion in 'Input System' started by Le-Capitaine, Dec 6, 2019.

  1. Le-Capitaine

    Le-Capitaine

    Joined:
    Jan 23, 2014
    Posts:
    33
    This is the only way I've found thus far to have multiple things at the player's command without violating the one PlayerInput rule. I've got a behaviour with an InputActionAsset and I'm looking to copy some of its Actions into InputActions on it. Problem being, it's apparently not as simple as

    myInputAction = myInputActionMap.GetAction ()


    so I'm stumped thus far.

    e: I am a F***ing idiot.
    I had a * on my upper bracket.
    This never happened, everybody.

    e2: I am doubly a F***ing idiot, because it still doesn't work. My code is

    Code (CSharp):
    1.  
    2.  
    3.     public void Init (InputActionAsset actions) {
    4.  
    5.         GetBindings (actions, volumeButton, "Music/Volume");
    6.         GetBindings (actions, volumeUp, "Music/Volume Up");
    7.         GetBindings (actions, volumeDown, "Music/Volume Down");
    8.         GetBindings (actions, skipTrack, "Music/Skip Track");
    9.  
    10.         //...
    11.     }
    12.     void GetBindings (InputActionAsset actions, InputAction action, string mapActionString) {
    13.         InputAction mapAction = actions.FindAction (mapActionString);
    14.         action = mapAction.Clone ();
    15.         foreach (InputBinding b in mapAction.bindings) action.AddBinding (b);
    16.     }
    17.  
    e3: Got it. Removed the middle line in GetBindings, which got the binding to work, and got my special interactions by manually setting them in the inspector for the behaviour's prefab.
    guess who's still an idiot
     
    Last edited: Dec 6, 2019