Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Listening to the new Input System's button press

Discussion in 'Input System' started by Kellphy, May 8, 2022.

  1. Kellphy

    Kellphy

    Joined:
    Jul 10, 2018
    Posts:
    4
    Hello,
    I can't get my head around to why I can't listen to the "onAnyButtonPress" observable for button presses. Here it is in the migrating docs: https://docs.unity3d.com/Packages/c...gine_InputSystem_InputSystem_onAnyButtonPress


    Code (CSharp):
    1.     private IDisposable m_EventListener;
    2.  
    3.     void OnEnable()
    4.     {
    5.         m_EventListener = InputSystem.onAnyButtonPress.Call(OnButtonPressed);
    6.     }
    7.  
    8.     void OnDisable()
    9.     {
    10.         m_EventListener.Dispose();
    11.     }
    12.  
    13.     void OnButtonPressed(InputControl button)
    14.     {
    15.         Debug.Log(button.name);
    16.     }
    Code (csharp):
    1. ArgumentException: Event must be a StateEvent or DeltaStateEvent but is a TEXT instead
    2. Parameter name: eventPtr
    3. UnityEngine.InputSystem.InputControlExtensions.EnumerateControls (UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr, UnityEngine.InputSystem.InputControlExtensions+Enumerate flags, UnityEngine.InputSystem.InputDevice device, System.Single magnitudeThreshold) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Controls/InputControlExtensions.cs:1012)
    4. UnityEngine.InputSystem.InputControlExtensions.GetFirstButtonPressOrNull (UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr, System.Single magnitude, System.Boolean buttonControlsOnly) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Controls/InputControlExtensions.cs:1105)
    5. UnityEngine.InputSystem.InputSystem+<>c.<get_onAnyButtonPress>b__79_0 (UnityEngine.InputSystem.LowLevel.InputEventPtr e) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/InputSystem.cs:2404)
    6. UnityEngine.InputSystem.LowLevel.SelectObservable`2+Select[TSource,TResult].OnNext (TSource evt) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Utilities/Observables/SelectObservable.cs:43)
    7. UnityEngine.InputSystem.LowLevel.InputEventListener+ObserverState.<.ctor>b__2_0 (UnityEngine.InputSystem.LowLevel.InputEventPtr eventPtr, UnityEngine.InputSystem.InputDevice device) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Events/InputEventListener.cs:127)
    8. UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue1,TValue2] (UnityEngine.InputSystem.Utilities.CallbackArray`1[System.Action`2[TValue1,TValue2]]& callbacks, TValue1 argument1, TValue2 argument2, System.String callbackName, System.Object context) (at Library/PackageCache/com.unity.inputsystem@1.3.0/InputSystem/Utilities/DelegateHelpers.cs:71)
    9. UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
    10. UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
    Code (csharp):
    1.  
    2. ArgumentException while executing 'InputSystem.onEvent' callbacks
    3. UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
    4. UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)
    5.  
     
    ljorgen12 likes this.
  2. ljorgen12

    ljorgen12

    Joined:
    Jan 5, 2021
    Posts:
    3
    I listen to onAnyButtonPress in order to join player and it works but I will occasionally get
    ArgumentException: Event must be a StateEvent or DeltaStateEvent but is a TEXT instead
    even while not playing
     
  3. andrew_oc

    andrew_oc

    Unity Technologies

    Joined:
    Apr 16, 2021
    Posts:
    77
    Is this happening with Input System 1.3? I remember seeing a fix for something similar a while back. If it is, would you be able to file a bug report for this one please so we can take a closer look? (Help -> Report a bug...)
     
  4. Kellphy

    Kellphy

    Joined:
    Jul 10, 2018
    Posts:
    4
    It is indeed 1.3.0. I just filed the bug report. Thank you! :D
     
  5. aydin_khp

    aydin_khp

    Joined:
    May 15, 2020
    Posts:
    29
    I'm experiencing the same issue now. Are there any updates?
     
  6. Kellphy

    Kellphy

    Joined:
    Jul 10, 2018
    Posts:
    4
    Yes, this is the response for the bug submission:
    "Thanks for reporting this issue, after some investigation we have found that it's already fixed in Unity 2022.1.0a16 and above."
     
  7. aydin_khp

    aydin_khp

    Joined:
    May 15, 2020
    Posts:
    29
    What about the LTS version. Is it fixed there as well?

    Could you please point me to the bug?
     
    Last edited: Jun 6, 2022
  8. Kellphy

    Kellphy

    Joined:
    Jul 10, 2018
    Posts:
    4
    Nope, it is not fixed in the 2021 LTS.
     
    aydin_khp likes this.
  9. FullMe7alJacke7

    FullMe7alJacke7

    Joined:
    Dec 17, 2013
    Posts:
    55
    Unfortunately that does not seem to be true in my instance.
    2022.1.6f1

    Code to replicate:

    Code (CSharp):
    1. InputSystem.onAnyButtonPress.Call(ctrl => Debug.Log(ctrl.displayName));
     
  10. MountainAura

    MountainAura

    Joined:
    Jul 2, 2021
    Posts:
    3
    In 2021LTS - Player Setting - Active Input Handlling
    set to "Both", same problem is encountered in the Tmp_Text Input
     
  11. ASquareDevs

    ASquareDevs

    Joined:
    Jun 2, 2021
    Posts:
    5
    I ran into the same issue today and found this forum post about it.

    After testing versions 1.2 -> 1.3 -> 1.4.2, I have found that the errors disappeared after upgrading to 1.4.2. 1.3 was still giving the same errors as reported above.