Search Unity

Question Update to 1.1.1 - multi-binding Actions no longer working

Discussion in 'Input System' started by pitchblende, Sep 21, 2021.

  1. pitchblende

    pitchblende

    Joined:
    Jan 9, 2020
    Posts:
    71
    I updated from Input System 1.1.0-preview.5 to 1.1.1 (I also tried 1.1.0-pre.6 with the same result as 1.1.1) and I seem to have a non-functional input system now. I can roll back to 1.1.0-pre.5 and everything starts working correctly again. Back to 1.1.1 and (even after a Unity restart) it's broken.

    All of my existing Input Actions that had multiple bindings on them seem either inert (don't produce any changing values when I move pedals, joystick, gamepad analog paddles, etc), or only output a fixed value of around 0.501 (not exactly 0.5). After removing all other bindings except for keyboard bindings, these Input Actions now only show a ReadValue of 0.0 regardless of keyboard state. Usually the value jumps to 1.0 when I hit the bound key.

    Additionally, when I try to open the Input Debug window (under Analysis), sometimes I get the following error over-and-over at high speed:

    Code (CSharp):
    1. ArgumentNullException: Value cannot be null.
    2. Parameter name: layoutName
    3. UnityEngine.InputSystem.Editor.EditorInputControlLayoutCache.GetIconForLayout (System.String layoutName) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Editor/EditorInputControlLayoutCache.cs:151)
    4. UnityEngine.InputSystem.Editor.EditorInputControlLayoutCache.GetIconForLayout (System.String layoutName) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Editor/EditorInputControlLayoutCache.cs:176)
    5. UnityEngine.InputSystem.Editor.InputDebuggerWindow+InputSystemTreeView.AddControlLayoutItem (UnityEngine.InputSystem.Layouts.InputControlLayout layout, UnityEditor.IMGUI.Controls.TreeViewItem parent, System.Int32& id) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Editor/Debugger/InputDebuggerWindow.cs:755)
    6. UnityEngine.InputSystem.Editor.InputDebuggerWindow+InputSystemTreeView.AddControlLayouts (UnityEditor.IMGUI.Controls.TreeViewItem parent, System.Int32& id) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Editor/Debugger/InputDebuggerWindow.cs:717)
    7. UnityEngine.InputSystem.Editor.InputDebuggerWindow+InputSystemTreeView.BuildRoot () (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Editor/Debugger/InputDebuggerWindow.cs:586)
    8. UnityEditor.IMGUI.Controls.TreeView+TreeViewControlDataSource.FetchData () (at <8d21067e8d9c494db25a2b2485216e63>:0)
    9. UnityEditor.IMGUI.Controls.TreeViewDataSource.ReloadData () (at <8d21067e8d9c494db25a2b2485216e63>:0)
    10. UnityEditor.IMGUI.Controls.TreeView+TreeViewControlDataSource.ReloadData () (at <8d21067e8d9c494db25a2b2485216e63>:0)
    11. UnityEditor.IMGUI.Controls.TreeViewController.ReloadData () (at <8d21067e8d9c494db25a2b2485216e63>:0)
    12. UnityEditor.IMGUI.Controls.TreeView.Reload () (at <8d21067e8d9c494db25a2b2485216e63>:0)
    13. UnityEngine.InputSystem.Editor.InputDebuggerWindow+InputSystemTreeView..ctor (UnityEditor.IMGUI.Controls.TreeViewState state) (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Editor/Debugger/InputDebuggerWindow.cs:407)
    14. UnityEngine.InputSystem.Editor.InputDebuggerWindow.Initialize () (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Editor/Debugger/InputDebuggerWindow.cs:167)
    15. UnityEngine.InputSystem.Editor.InputDebuggerWindow.OnGUI () (at Library/PackageCache/com.unity.inputsystem@1.1.1/InputSystem/Editor/Debugger/InputDebuggerWindow.cs:197)
    16. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    17. Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
    18. System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    19. System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <eae584ce26bc40229c1b1aa476bfa589>:0)
    20. UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at <8d21067e8d9c494db25a2b2485216e63>:0)
    21. UnityEditor.HostView.Invoke (System.String methodName) (at <8d21067e8d9c494db25a2b2485216e63>:0)
    22. UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <8d21067e8d9c494db25a2b2485216e63>:0)
    23. UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <8d21067e8d9c494db25a2b2485216e63>:0)
    24. UnityEditor.DockArea.OldOnGUI () (at <8d21067e8d9c494db25a2b2485216e63>:0)
    25. UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    26. UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    27. UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    28. UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    29. UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    30. UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    31. UnityEngine.UIElements.EventDispatchUtilities.PropagateEvent (UnityEngine.UIElements.EventBase evt) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    32. UnityEngine.UIElements.MouseEventDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    33. UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    34. UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    35. UnityEngine.UIElements.EventDispatcher.ProcessEventQueue () (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    36. UnityEngine.UIElements.EventDispatcher.OpenGate () (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    37. UnityEngine.UIElements.EventDispatcherGate.Dispose () (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    38. UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    39. UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    40. UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    41. UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    42. UnityEngine.UIElements.UIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <06214b245dbb4d10a9cefd10639bb04e>:0)
    43. UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <fe7ee1881b524b0d9443f74417fb598b>:0)
    44.  
    At this point I'm not really sure how to go about resolving this.

    My project is a Unity 2019.4 project. I created a brand new project with Unity 2021.1 and imported Input System 1.1.1 into it, and set up some similar Input Actions with multiple bindings, and they seem to work correctly, but unfortunately I am not in a position to upgrade my main project away from 2019.4.

    Should I expect Input System 1.1.1 to work with Unity 2019.4 or have I jumped the gun on this?
     
    Last edited: Sep 21, 2021
    reinfeldx likes this.
  2. pitchblende

    pitchblende

    Joined:
    Jan 9, 2020
    Posts:
    71
    I've created a fresh, new Input Action as a SerializedField on one of my components, set it to Value/Any, and bound a keyboard button to it with no Interactions or Processors. In code I've enabled the Action and set a callback on
    .started
    to print out a debug message. When I play the scene and hit the key, I see the message - good.

    But when I poll the value in
    Update()
    with
    action.ReadValue<float>()
    I'm just getting zero regardless of the keyboard button state. In earlier versions of Input System like 1.1.0-pre.5 this would return 0.0 when not pressed, and 1.0 when pressed. Has this changed in version 1.1.1 (and 1.1.0-pre.6)?

    EDIT: I changed the binding to a GamePad's analog right trigger and that just returns zero too, regardless of actual state.
     
  3. pitchblende

    pitchblende

    Joined:
    Jan 9, 2020
    Posts:
    71
    I created an almost exact duplicate of the scripted Component that has my broken Input Actions on it. I created the exact same set of bindings. Bizarrely, this new set of Input Actions polls the correct values and generally works properly, but the original Input Actions that were present when I upgraded the Input System package do not work at all (always return zero when polled).

    What kind of internal state could Input System be keeping? I've tried a complete project reimport (deleted the Library folder) and that hasn't made any difference. I notice that the fields in the .prefab file (that I happen to be using) are slightly different between the older Input Actions and the new ones - in particular the m_Name field in the newer Actions matches the name of the inspector field (at least as per Unity's normal name mangling rules), whereas my older Actions have legacy names from a long time ago. I may try manually changing those to see if that makes any difference. Everything else in the .prefab file looks prety much the same between both instances, including the m_Path and m_Flags fields in the m_SingletonActionBindings lists.

    What else could it be?
     
  4. pitchblende

    pitchblende

    Joined:
    Jan 9, 2020
    Posts:
    71
    I think I've worked it out - in my code I am making calls to
    ReadValue<float>()
    within
    FixedUpdate()
    , as I am using those values to affect physics.

    I notice in the Input System Package section of Project Settings, there is "Update Mode: Process Events in [Dynamic|Fixed] Update". I have mine set to Dynamic. I switched to polling the Action values in
    Update()
    and my previous functionality came back to life, all working as expected.

    I've looked through the 1.1.0-pre.6 changelog and I'm not seeing any obvious changes related to this.

    So is my conclusion correct? Is it no longer safe to poll Input Action values in
    FixedUpdate()
    if the mode is set to "Process Events in Dynamic Update"? Have I missed something in the docs about this, somewhere?

    If someone can shed some light on this change, I'd appreciate it, please. I want to understand why it used to work, and whether it was meant to work, or whether I made a mistake originally and it's finally bitten me.
     
    reinfeldx and NotaNaN like this.
  5. pitchblende

    pitchblende

    Joined:
    Jan 9, 2020
    Posts:
    71
    FWIW, even thoughj I now have working Input Actions by moving
    ReadValue()
    to
    Update()
    , I still get the blank Input Debug window and the "ArgumentNullException: Value cannot be null. Parameter name: layoutName" error fairly often.
     
    Last edited: Sep 24, 2021
  6. pitchblende

    pitchblende

    Joined:
    Jan 9, 2020
    Posts:
    71
    I found this third-party write-up of Input System from October 2020, not sure which version they used but it will definitely be before 1.1.0-pre.6:

    So it seems I wasn't the only person using
    ReadValue()
    in both
    Update()
    and
    FixedUpdate()
    .

    I also can't find any mention of this restriction in the official docs.

    I'm starting to wonder if this is a regression or an intended change, given that the Changelog doesn't mention it. Can anyone advise whether to report a bug or not?
     
  7. pitchblende

    pitchblende

    Joined:
    Jan 9, 2020
    Posts:
    71
    FWIW I filed a bug.
     
    Railon23, reinfeldx and NotaNaN like this.
  8. reinfeldx

    reinfeldx

    Joined:
    Nov 23, 2013
    Posts:
    164
    I just ran into a similar issue — I'm on 1.1.1.

    My issue: I'm trying to call ReadValue<Vector2>() in FixedUpdate and it's returning zero. If I move ReadValue to Update, it successfully returns a value. My update mode is set to Dynamic Update in project settings.

    @pitchblende Is your bug report something I can vote on to increase visibility? Link?

    Sorry you're in here talking to yourself, but your documenting this has been helpful to me, so thanks. Hopefully we can get a Unity comment on this... @Rene-Damm ?

    This tutorial shows successful polling for input in FixedUpdate (timestamp 14:48):

     
    Last edited: Oct 15, 2021
  9. pitchblende

    pitchblende

    Joined:
    Jan 9, 2020
    Posts:
    71
    @reinfeldx thanks for responding - talking to myself on these forums isn't too unusual unfortunately :)

    My bug report hasn't been triaged by Unity so there's no public link yet. Once that's done, if it's accepted, I'll post a link to it here. Last bug I reported took 6 weeks to be triaged so don't hold your breath. However this one seems serious enough that if I can just get someone at Unity to look at it then it'll probably be escalated pretty quickly. It breaks Cinemachine out-of-the-box too, so that might help.

    Also mentioned here: https://forum.unity.com/threads/version-1-1-and-general-update.1168469/#post-7518461
     
  10. pitchblende

    pitchblende

    Joined:
    Jan 9, 2020
    Posts:
    71
    @reinfeldx also, your situation sounds identical to mine. Just out of curiosity, if you change your Input System Update Mode to Fixed Update, does your original code work properly? In my case it does. In the case I've had with Cinemachine, "Smart Update" randomly fails because it dynamically switches between Late Update and Fixed Update according to some internal rule. This causes unusual intermittent interaction anomalies.
     
  11. reinfeldx

    reinfeldx

    Joined:
    Nov 23, 2013
    Posts:
    164
    Yep, it does.

    I also experimented with Manual Update mode, and the following seems to be working for me without issue also:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class PlayerController_Tutorial : MonoBehaviour
    5. {
    6.     private TestInputActions testInputActions;
    7.     private InputAction moveAction;
    8.  
    9.     private void Awake()
    10.     {
    11.         testInputActions = new TestInputActions();
    12.     }
    13.  
    14.     private void OnEnable()
    15.     {
    16.         moveAction = testInputActions.PlayerDefault.Move;
    17.         moveAction.Enable();
    18.  
    19.         testInputActions.PlayerDefault.Jump.performed += OnJump;
    20.         testInputActions.PlayerDefault.Jump.Enable();
    21.     }
    22.  
    23.     private void OnDisable()
    24.     {
    25.         moveAction.Disable();
    26.         testInputActions.PlayerDefault.Jump.performed -= OnJump;
    27.         testInputActions.PlayerDefault.Jump.Disable();
    28.     }
    29.  
    30.     private void OnJump(InputAction.CallbackContext context)
    31.     {
    32.         Debug.Log("Jumped");
    33.     }
    34.  
    35.     private void Update()
    36.     {
    37.         // Update the system manually if set to Manual in Project Settings
    38.         InputSystem.Update();
    39.         Debug.Log($"Update movement values: {moveAction.ReadValue<Vector2>()}");
    40.     }
    41.  
    42.     private void FixedUpdate()
    43.     {
    44.         // Update the system manually if set to Manual in Project Settings
    45.         InputSystem.Update();
    46.         Debug.Log($"FixedUpdate movement values: {moveAction.ReadValue<Vector2>()}");
    47.     }
    48. }
    With prior projects I've become used to polling for different inputs in Update and FixedUpdate, which is why I tried this. But as I think about it now it might not be necessary due to the event-based approach of the New Input System. It's my first day with it, so I could be wrong on any of this :)
     
  12. pitchblende

    pitchblende

    Joined:
    Jan 9, 2020
    Posts:
    71
    Ok, cool - the more people that reproduce this and report it, the more likely it'll get addressed. I've been through my entire project and moved all
    ReadValue()
    calls to Update() only, so I'm no longer blocked by it, but it would be great to see this fixed soon.
     
  13. dmytro_at_unity

    dmytro_at_unity

    Unity Technologies

    Joined:
    Feb 12, 2021
    Posts:
    212
    Hey folks, just want to let you know that we just landed the fix for this in https://github.com/Unity-Technologies/InputSystem/pull/1424 it will be part of 1.1.2 which will be released very soon.

    The problem was specific to running in play mode in the editor. Reading values from FixedUpdate would return values from last frame's editor update. We restored behavior from <1.1.0-pre.6 which is reading in FixedUpdate will return _last_ frame's player data. If you have to get same frames data in FixedUpdate you will need to switch input system to process updates in fixed updates in the project settings.
     
    pitchblende likes this.
  14. pitchblende

    pitchblende

    Joined:
    Jan 9, 2020
    Posts:
    71
    @dmytro_at_unity thanks for the update - glad to see some movement on this.
     
    Crazycarpet likes this.