Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Input System doesn't trigger anything anymore

Discussion in 'Input System' started by MetalFox, Jul 27, 2019.

  1. MetalFox

    MetalFox

    Joined:
    May 14, 2014
    Posts:
    10
    Hello !

    TL;DR : InputSystem worked some days ago, don't trigger anything anymore, halp.

    I tried the new Input System some days ago, and that's really neat ! I did a lot of stuff, trying to understand the best way to use it, and, in the end, I had a character jumping and moving everywhere, that was cool ! Then, I merged my code in our develop branch and went to bed.

    Today, I want to continue my code, but my character doesn't move anymore, Actions are not triggered (even if inputs are detected in debugger) and I really don't know why. Either the code merge overwrote some important settings (I know what you're thinking and yes, the "Active Input Handling" is set on "Both" and I tried only running the preview) or I did something important during my little tests and I didn't realize.

    So I decided to try to reproduce my steps on a fresh new project, maybe you guys can help me figure what do I do wrong ?

    1/ Create a new 2D project (via the Hub)

    2/ Install the latest Package (version 0.9.0)

    3/ Click Yes on that message prompt to activate the new Input management in the settings
    upload_2019-7-27_13-50-34.png

    4/ Restart Unity Editor since it didn't restart even if the message said it would and check the project settings (yes, it's on "Both", and yes, my Scripting Runtime Version is 4.0)
    upload_2019-7-27_13-52-24.png

    5/ Create a new GameObject and add a PlayerInput on it

    6/ Click on "Open Input Settings" and create an "InputSettings" asset

    7/ Click on "Create Actions..." to create my ActionMap asset

    8/ Create a "TestAction" on my "Player" ActionMap and set it to the key "t"

    upload_2019-7-27_14-0-43.png

    9/ Create a new Script "TestScript" that contains a OnTestAction() method (that only logs "test") and enables the test map/action (just to be sure) :

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEngine.InputSystem;
    4. using UnityEngine.InputSystem.PlayerInput;
    5.  
    6. public class TestScript : MonoBehaviour
    7. {
    8.     void Start()
    9.     {
    10.         InputActionMap playerActionMap = GetComponent<PlayerInput>().actions.GetActionMap("Player");
    11.         playerActionMap.Enable();
    12.         playerActionMap.GetAction("TestAction").Enable(); //Just to be sure
    13.     }
    14.  
    15.     public void OnTestAction()
    16.     {
    17.         Debug.Log("test");
    18.     }
    19. }
    20.  
    10/ Pressing "Play" and spamming "T" like a madman to try to display a debug (note that, in the debugger, a User is created, my "t" presses are detected, my TestAction exists and is mapped on the "t" key but no debug is displayed
    upload_2019-7-27_14-14-50.png

    It's probably a silly problem, but it's driving me crazy, what do I do wrong ? It's even more infuriating that it worked some days ago !

    Additional information :
    - Switching the Input Management from "Both" to "New Input System (preview) does nothing
    - Checking in Update() is my action is enabled returns "True" every frame
    - Checking in Update() is my action is triggered returns "False" every frame
    - Using action.started/triggered/performed does nothing (I tried also switching to UnityEvent or C# events for this) :

    Code (CSharp):
    1. public class TestScript : MonoBehaviour
    2. {
    3.     InputAction a;
    4.  
    5.     void Start()
    6.     {
    7.         InputActionMap playerActionMap = GetComponent<PlayerInput>().actions.GetActionMap("Player");
    8.         playerActionMap.Enable();
    9.         a = playerActionMap.GetAction("TestAction");
    10.         a.Enable(); //Just to be sure
    11.         a.started += OnTriggeredTestAction;
    12.         a.performed += OnTriggeredTestAction;
    13.         a.canceled += OnTriggeredTestAction;
    14.     }
    15.  
    16.     public void OnTestAction()
    17.     {
    18.         Debug.Log("test");
    19.     }
    20.  
    21.     public void OnTriggeredTestAction(InputAction.CallbackContext ctx)
    22.     {
    23.         Debug.Log("test triggered");
    24.     }
    25. }
    - Injecting directly the InputActionReference of my TestAction and using it does nothing
    - Forcing "Default Control Scheme" and "Default Action Map" does nothing
    - Using BroadcastMessage or UnityEvents doesn't work
     

    Attached Files:

    tonytopper and adnanzmn97 like this.
  2. SnowshoeNyan

    SnowshoeNyan

    Joined:
    Jul 16, 2019
    Posts:
    1
    This happens to me too .-.
     
  3. Stephano

    Stephano

    Joined:
    May 10, 2013
    Posts:
    5
    martyparty1535 and adnanzmn97 like this.
  4. MetalFox

    MetalFox

    Joined:
    May 14, 2014
    Posts:
    10
  5. alternativevisual

    alternativevisual

    Joined:
    Apr 16, 2015
    Posts:
    75
    I'm having the same problem. And sadly, reboot doesn't helps anything.
    The funny thing is that when i first imported input package, the samples were working perfectly. But when i started to make my controls, generated c# class and implement interfaces, then it stopped working.
    Switching back to old input system, again.. ;(
     
  6. Yecats

    Yecats

    Joined:
    Jul 13, 2014
    Posts:
    69
    @MetalFox (and others) - As a side note, If you do not have a Default Action Map defined in the PlayerInput component, nothing will get routed. It looks like this may have also been a factor, based on your screenshot.

    upload_2019-10-19_15-52-37.png
     
    SparkesRS likes this.
  7. alternativevisual

    alternativevisual

    Joined:
    Apr 16, 2015
    Posts:
    75
    My gosh.. This new input system is SOO disgustingly unstable.

    1) It doesn't work when i adding any control scheme
    2) Then Player Input works only with SendMessages or BroadcastMessages behavior
    3) They are dropping fps to zero (with SendMessages), or gives frequent one frame lags with BroadcastMessages. (maybe it's because of debug logs)
    4) Interfaces implementation (from generated C# class) doesn't work as well

    How in the earth i should work with this?
     
    Last edited: Oct 20, 2019
    mrkzzz, Tony_Max, Ghosthowl and 3 others like this.
  8. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Just to make sure I follow. With the current setup you have, if you choose SendMessages or BroadcastMessages, input is indeed coming through as you expect. I.e. all methods are getting called in accordance to input.

    But then, if you switch to UnityEvents and select methods to call for each event, the respective method is *NOT* getting called?

    It is. Many events are high-frequency. Debug.Logs are very expensive (because of the cost of extracting stack traces and in the editor, also due to the cost incurred by the console view which does some expensive searches internally).

    The C# code-generation workflow and PlayerInput are currently not combinable. We'll be looking for ways to use the two together after 1.0.
     
    tonytopper likes this.
  9. alternativevisual

    alternativevisual

    Joined:
    Apr 16, 2015
    Posts:
    75
    Player Input doesn't work at all when i have any "Control Scheme"
    When i don't have it .. It doesn't work as well: upload_2019-10-24_16-35-3.png
    (UnityEvents)
    upload_2019-10-24_16-35-35.png
    (SendMessages / Broadcast)
    Invoke C Sharp Events doesn't call anything at all.


    I've got Input System to work, but without Player Input or C# generated class.
    I'm just directly adding callback methods like this:
    upload_2019-10-24_15-52-20.png

    upload_2019-10-24_15-54-4.png

    I think it should be built-in methods. It's so easy to work with, and it doesn't require C# generated class.

    And, by the way, after i've finally got it to work, New System have impressed me - it's 1000x times better than old system! Cudos! :)
    But i hope it will be more user friendly (especially for not programming people) and Player Input will be fixed
     
    Daedolon likes this.
  10. drhodor

    drhodor

    Joined:
    Aug 18, 2013
    Posts:
    39
    Everything will also stop working if you delete an old InputActions asset + generated code and try to start with a new one in a project. Even after rebuilding library, which is a bummer.
     
  11. JeffBert

    JeffBert

    Joined:
    Apr 16, 2013
    Posts:
    2
    Any fix for this? The input system is unusable for me because of this. It was working fine before I deleted an old InputActions asset.
     
  12. Grinning-Pickle

    Grinning-Pickle

    Joined:
    Feb 4, 2013
    Posts:
    7
    I thought I'd try this package because it seemed interesting. Unfortunately, issues like this are just mindboggling. You can build a whole fancy system but when inputs get completely ignored, what's the point? Should I ask my players to make sure to reboot their PC before playing my game? No one will and no one should use this package because it doesn't work. Endlessly frustrating and embarrassing.
     
    Waz and JuanFPG like this.
  13. Stefferp

    Stefferp

    Joined:
    Nov 18, 2018
    Posts:
    4
    Hi, could you share that full class? I'm having the same problem too and your solution seems nice and simple. Thanks!
     
  14. midsummer

    midsummer

    Joined:
    Jan 12, 2017
    Posts:
    38
    I updated a project I hadn't touched for a while to the latest 2020.2.0b8 beta. Everything worked, with the exception of all keyboard / mouse input. After spending some time fiddling with the PlayerInput component and inspecting my scripts, I noticed that the value of the Active Input Handling setting had reverted back to Input Manager (old) in Project Settings.

    In this case you'd think that the most simple solution to input not registering would be setting this value back to Input System Package (new) or Both... It would, however, seem that the value can't currently be changed due to some bug or another. Trying to do that just leaves the setting unmodified and writes this error to the console:


    Cancelling Display Dialog : This should not be called when a View's DrawRect Method is in progress


    All other project settings seem to be correct. Only this one detail has been affected by something, likely the process of updating the project for a newer Unity editor version?

    Input System package version is 1.0. I think it was the same before I updated the project.


    EDIT: Apparently the bug with the value of Active Input Handling resetting is a known issue in 2020.2 beta, and will be fixed. Just in case somebody ran into the same problem.
     
    Last edited: Oct 28, 2020
    _slash_ likes this.
  15. _slash_

    _slash_

    Joined:
    Mar 26, 2013
    Posts:
    37

    I have the exact same issue, I even tried thought code using "enableNativePlatformBackendsForNewInputSystem" but the key is not found...

    This works:

    Code (CSharp):
    1. var property = GetPropertyOrNull("activeInputHandler");
    2. var value = 2; //(0: old, 1: new, 2:both)
    3. if (property != null)
    4. {
    5.     property.intValue = value;
    6.     property.serializedObject.ApplyModifiedProperties();
    7. }
     
  16. midsummer

    midsummer

    Joined:
    Jan 12, 2017
    Posts:
    38
    Thanks for the tip, looks like a working workaround. However it would seem that the issue has been fixed in the latest beta version 2020.2.0b14 that I just updated my project to. InputSystem package version is 1.1.0-preview2.
     
  17. EmretheGanjaRaiders

    EmretheGanjaRaiders

    Joined:
    Dec 27, 2014
    Posts:
    21
    my character was able to enter a car and drive it since i build the game it doesnt work anymore. i can run and do everything in the first action map but in the second action map nothing work. in the editor it doesnt work too
     
  18. SaltwaterAssembly

    SaltwaterAssembly

    Joined:
    Mar 8, 2016
    Posts:
    95
    Such an obtuse system
     
    halley, chloelcdev, Waz and 5 others like this.
  19. UnityMaru

    UnityMaru

    Community Engagement Manager PSM

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    Please avoid making multiple posts with little to not context. We definitely value feedback, but please try to do this constructively with the one post.
     
    JuanFPG likes this.
  20. giovannazanella

    giovannazanella

    Joined:
    Oct 29, 2018
    Posts:
    4
    I switched my input system to the new one yesterday and everything was working fine, however today immediately after loading the project, my player wasn't even moving.

    After some investigating I realized the problem was that I was calling an action .performed on Awake on one script, while referencing the Input Asset on another script's Awake method. After moving the call to Start ( ) it seems to be working again.

    I am not sure how this was working yesterday though, would appreciate if someone could shine a light on this.
     
  21. Arc-fy

    Arc-fy

    Joined:
    Feb 9, 2020
    Posts:
    7
    Has this been fixed in 1.3? Looks like it might have gotten lost during the bug reporting migration.

    I get the issue where my devices randomly stop working and remain that way even after game restart, but the keyboard still always worked, so I'm wondering if that was related to this.
     
  22. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    220
    Having a similar issue in 2022.2.x with 1.4.4.

    I am using the "Generate C# Class" option. Does the Player Input module still not work with that? That seems unacceptable at this stage without at least a warning message in the Inspector on the component.
     
  23. Waz

    Waz

    Joined:
    May 1, 2010
    Posts:
    287
    I found a comment from a couple of years ago saying they would fix it before 1.0. But who knows. It seems to be working for me so far, but I've only just started a new project and can't even get this "new" system to work at runtime at all.
     
  24. Tony_Max

    Tony_Max

    Joined:
    Feb 7, 2017
    Posts:
    340
    2023 year, one another thread full of mentions of issue with input system. I'm a bit tired already because any package I start to use has at least couple of unsolved dev-stop issues.

    I have exact same issue: when I changing anything in my scheme, for example
    ActionType
    in
    Jump
    action, whole
    InputActionAsset
    stop working, while another one with near same inputs WORKS! I even see in input debugger that input system gets keys pressed on my keyboard. After rebooting unity all just magically got working.

    upload_2023-4-25_12-45-43.png

    Unity v2022.2.15, Input System 1.5.1

    I just don't understand how you want from us to make games, for example VR based, when your fundamental systems refuses to work. How should I now change my controls? Leave them unchanged because unity decides that it is enough of editing for me?

    In my particular case it was ProjectSettings -> Editor -> EnterPlayModeOptions which should have ReloadDomain enabled. It seems like Input System has some static state, which should be cleared before new play.
    IMHO it should force domain reload if it need one.
     
    Last edited: Apr 25, 2023
  25. bonickhausen

    bonickhausen

    Joined:
    Jan 20, 2014
    Posts:
    115
    I'm really glad I checked this subforum before going with the new input system for my new project. Guess I'll just stick to good ol Rewired!
     
    Tony_Max likes this.
  26. andrlz

    andrlz

    Joined:
    Mar 15, 2021
    Posts:
    6
    Similar issue here. I'm working with the PlayerInput component, in a multiplayer setup, in which I spawn each player after spawning a PlayerInputManager. The PlayerInputManager's Join Behaviour is set to Join When Button Pressed.

    The only way I could get it to work:

    1. choosing the Send Messages method
    2. safety checking all objects I got at Start() both in the abstract class the player script inherits from and in the player script itself.

    Code (CSharp):
    1.  protected override void Start()
    2.     {
    3.         animator = GetComponent<Animator>();
    4.         spriteRenderer = GetComponent<SpriteRenderer>();
    5.        
    6.         playerInput = GetComponent<PlayerInput>();
    7.         movement = playerInput.actions.FindAction("Move");
    8.         // register itself
    9.         GameManager.Instance.AddPlayer(this);
    10.        
    11.        
    12.         base.Start();      
    13.     }
    And here's in the OnMove method in which I'm receiving messages. I added the logic for movement inside it and had to wrap all the references to components I got at Start around safety checks. I had to do the same safety checks in the abstract class from where I'm inheriting the player script . I think that's related to your issue ( the action being processed out of sync with the GetComponent calls at Start / Awake)

    Code (CSharp):
    1. public void OnMove()
    2.     {
    3.         if(movement == null || playerInput == null)
    4.         {
    5.             playerInput = GetComponent<PlayerInput>();
    6.             movement = playerInput.actions.FindAction("Move");
    7.         }
    8.         int vertical = (int) movement.ReadValue<Vector2>().y;
    9.         int horizontal = (int) movement.ReadValue<Vector2>().x;
    10.         if(horizontal == 0 && vertical == 0)
    11.         {
    12.             base.Body.velocity = Vector2.zero;
    13.             hasJumped = false;
    14.             return;
    15.         }
    16.  
    17.         if(horizontal != 0)
    18.         {
    19.             hasJumped = false;
    20.  
    21.             if(animator == null)
    22.                 animator = GetComponent<Animator>();
    23.  
    24.             animator.SetTrigger("walk");
    25.             if((horizontal > 0 && facingRight) || (horizontal < 0 && !facingRight))
    26.             {
    27.                 flip();
    28.                 return;
    29.             }
    30.             vertical = 0;
    31.            
    32.             AttemptMove<Chest>(horizontal, vertical);
    33.         }
    34.        
    35.         if(vertical != 0 && !hasJumped)
    36.         {
    37.             if(animator == null)
    38.                 animator = GetComponent<Animator>();
    39.  
    40.             animator.SetTrigger("jump");
    41.             hasJumped = true;
    42.             horizontal = 0;
    43.         }
    44.         if(vertical != 0)
    45.         {
    46.             AttemptMove<Chest>(horizontal, vertical);
    47.         }
    48.  
    49.     }
    There was no way I could do like shown below, as in the SimpleController_UsingPlayerInput sample:

    Code (CSharp):
    1.  public void OnMove(InputAction.CallbackContext context)
    2.     {
    3.         m_Move = context.ReadValue<Vector2>();
    4.     }
    I still think the unity guys are doing a great job with this new input system. The documentation is on point (may even be too thorough, as there's so many options it can be daunting for a beginner) most samples are great, too (despite that one not working for me). It took me less that 45 minutes to set up a multiple device multiplayer prototype, with very little coding!
     
  27. Yaver_Abbasov

    Yaver_Abbasov

    Joined:
    Jan 15, 2017
    Posts:
    7
    If I make an assumption, the reason for this is that it does not support our external (Keyboard and Mouse). I don't know why, but the problem seems to be solved when I use the Generated class instead of the PlayerInput class.

    unsupported Devices in Input List.png



    generate c class.png


    asdasd.png