Search Unity

[Solved] Can't make it work

Discussion in 'Input System' started by illinar, Oct 16, 2019.

  1. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    Code (CSharp):
    1. public class CameraControlInput : MonoBehaviour
    2. {
    3.     private InputActions _inputActions;
    4.  
    5.     void Awake()
    6.     {
    7.         Debug.Log("awake");
    8.         _inputActions = new InputActions();
    9.         _inputActions.Building.PrimaryAction.performed += a => Debug.Log("qwfqwf");
    10.     }
    11. }
    upload_2019-10-16_17-56-12.png

    Is this supposed to work?

    I tried binding all the actions, none of them give me any callbacks. What am I missing? Thanks.

    A little offtopic, but do I need to remove the callback when object gets destroyed, or when InputActions instance goes out of scope I don't need to worry about it?
     
  2. WizByteGames

    WizByteGames

    Joined:
    Mar 28, 2013
    Posts:
    70
    You have to enable the action before it can be used.

    So you would call _inputActions.Building.PrimaryAction.Enable();
     
  3. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    863
    Thank you, that works. Or in my case
    _inputActions.Building.Enable()
    is what I'm gonna be using.