Search Unity

[Solved] Using InputActionReference

Discussion in 'Input System' started by joshcamas, Oct 15, 2019.

  1. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,278
    Hello,

    I have a field on my monobehavior that is a InputActionReference.

    I'd like to hook a function to this input action, I've tried both of these options and neither of them seem to trigger:
    Code (CSharp):
    1. //Doesn't work
    2. interactAction.action.performed += OnInteractAction;
    3.  
    4. //Doesn't work either
    5. interactAction.ToInputAction().performed += OnInteractAction;
    Am I missing something? I figured using the reference is the best way to do it, since I've created it as an asset in a asset map, and I'd just like to reference that action asset.
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Is the action getting enabled? After calling InputAction.Enable on the action, the above code is expected to work.
     
  3. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    1,278
    Ah, that worked! Thank you :))
     
  4. LudiKha

    LudiKha

    Joined:
    Feb 15, 2014
    Posts:
    140
    @Rene-Damm Either of these still aren't working for me, even though I've enabled the InputAction. Any ideas?
     
  5. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    What's the debugger saying? (Window >> Analyze >> Input Debugger) It should show all the actions in play along with their bound controls.