Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

[Solved] Can't make it work

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

  1. illinar

    illinar

    Joined:
    Apr 6, 2011
    Posts:
    864
    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:
    864
    Thank you, that works. Or in my case
    _inputActions.Building.Enable()
    is what I'm gonna be using.