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

SOLVED Cant Get input Events To Happen

Discussion in 'Input System' started by Linus, Oct 25, 2019.

  1. Linus

    Linus

    Joined:
    Feb 22, 2012
    Posts:
    112
    This should work right?
    I have a similar setup in a project made in 2019.3.0b4 (or was it b3)
    And that project still works in b8
    But in any new projects I make I cant get the new input system to work.

    Active Input Handling in player settings is Both (also tried with input system only)

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.InputSystem;
    4.  
    5. public class AnyKeyTest : MonoBehaviour
    6. {
    7.     public  InputActionAsset inputActionAsset;
    8.  
    9.     InputAction action;
    10.  
    11.     private void Awake( )
    12.     {
    13.         var inputActions = inputActionAsset.FindActionMap( "any" );
    14.         action = inputActions.FindAction( "any" );
    15.        
    16.     }
    17.  
    18.     private void OnEnable( )
    19.     {
    20.         action.started += OnStarted;
    21.         action.performed += OnPerformed;
    22.         action.canceled += OnCanceled;
    23.        
    24.     }
    25.  
    26.     private void OnDisable( )
    27.     {
    28.  
    29.         action.started -= OnStarted;
    30.         action.performed -= OnPerformed;
    31.         action.canceled -= OnCanceled;
    32.  
    33.     }
    34.  
    35.     private void OnStarted( InputAction.CallbackContext obj )
    36.     {
    37.         Debug.Log( "started" );
    38.     }
    39.  
    40.     private void OnCanceled( InputAction.CallbackContext obj )
    41.     {
    42.         Debug.Log( "canceled" );
    43.     }
    44.  
    45.  
    46.  
    47.  
    48.     public void OnPerformed( InputAction.CallbackContext obj )
    49.     {
    50.         Debug.Log( "Performed" );
    51.     }
    52. }
     
  2. SomeGuy22

    SomeGuy22

    Joined:
    Jun 3, 2011
    Posts:
    722
    Debug log your InputAction.phase and see if the current state is "Disabled". If so, you will need to Enable it by doing InputActionAsset.Enable() in Awake(). If not, check your bindings again and ensure they are setup correctly.
     
  3. Linus

    Linus

    Joined:
    Feb 22, 2012
    Posts:
    112
    Oh my how did I miss that
    Thank you so much
     
    SomeGuy22 likes this.