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’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Bug Quite bad bug where inputs without modifiers stop being read

Discussion in 'Input System' started by unormal, Jun 1, 2023.

  1. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
    Got a gnarly one with a simple reproduction.

    If you create multiple commands, one for example for key w and one for ctrl+w, and then while reading the w input, disable the layer containing the commands, later when you re-enable the layer, the new input system won't respond to the command mapped to ctrl+w at all until the actions/devices are manually Reset()!

    My guess is the internal tracking state likely becomes corrupt when disabled.

    Though in the end the repro was simple, I struggled with this one for weeks trying to understand why some commands weren't working intermittently. Quite a nasty issue, and it's unclear if issuing Resets that frequently is causing additional issues.

    Submitted a repro as case IN-42617; the simple code to repro below (alongside an event system with a new input system component)

    1. Press ctrl+w you will see the "with modifier" command properly being read.

    2. Press w and you will see "witohut modifier" command properly being read.

    3. Press 2 to re-enable the input map.

    4. ctrl+w no longer works!

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.InputSystem;
    5. using UnityEngine.UI;
    6.  
    7. public class Controller : MonoBehaviour
    8. {
    9.     InputActionMap map,map2;
    10.  
    11.     InputAction one,onen,sw1,sw2;
    12.     void Start()
    13.     {
    14.         map = new InputActionMap();
    15.         map2 = new InputActionMap();
    16.  
    17.  
    18.         onen = map.AddAction("one", InputActionType.Button);
    19.         onen.AddBinding("<Keyboard>/w");
    20.         onen.AddBinding("<Gamepad>/buttonSouth");
    21.  
    22.         one = map.AddAction("one+ctrl", InputActionType.Button );
    23.         one.AddCompositeBinding("OneModifier")
    24.             .With("Binding", "<Keyboard>/w")
    25.             .With("Modifier", "<Keyboard>/ctrl");
    26.         one.AddCompositeBinding("OneModifier")
    27.             .With("Binding", "<Gamepad>/buttonSouth")
    28.             .With("Modifier", "<Gamepad>/leftTrigger");
    29.  
    30.         sw1 = map2.AddAction("sw1", InputActionType.Button);
    31.         sw1.AddBinding("<Keyboard>/1");
    32.         sw1.AddBinding("<Gamepad>/buttonWest");
    33.  
    34.         sw2 = map2.AddAction("sw2", InputActionType.Button);
    35.         sw2.AddBinding("<Keyboard>/2");
    36.         sw2.AddBinding("<Gamepad>/buttonNorth");
    37.  
    38.         map.Enable();
    39.         map2.Enable();
    40.     }
    41.  
    42.     // Update is called once per frame
    43.     void Update()
    44.     {
    45.         if( sw1.WasPerformedThisFrame())
    46.         {
    47.             UnityEngine.Debug.Log("disable map");
    48.             map.Disable();
    49.         }
    50.  
    51.         if (sw2.WasPerformedThisFrame())
    52.         {
    53.             UnityEngine.Debug.Log("enable map");
    54.             map.Enable();
    55.         }
    56.  
    57.         if (one.WasPerformedThisFrame())
    58.         {
    59.             UnityEngine.Debug.Log("Action WITH MODIFIER (1) performed");
    60.         }
    61.  
    62.         if (onen.WasPerformedThisFrame())
    63.         {
    64.             UnityEngine.Debug.Log("Action (1) performed");
    65.             map.Disable(); // <--- Disabling it inside the update frame with this kind of rig seem to kill modifier tracking until the device/aciton is reset!
    66.         }
    67.     }
    68.  
    69. }
    70.  
     
    mochida_preferred likes this.
  2. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
    This was confirmed by QA case IN-42617/ISXB-505

    This is an extremely critical bug, because while the sample above is contrived, the case where it triggers is pretty simple in practice:

    1. press a button with a modifier that opens a new menu
    2. the new menu switches up some layers (disabling one that was used to trigger it)
    3. return to the previous menu or game view
    4. quite a lot of controls are now permanently broken!
     
    Last edited: Jun 2, 2023
    mochida_preferred likes this.