Search Unity

Trigger input actions manually / Reset input state (New Input System)

Discussion in 'Input System' started by Knosis_Co-Verse, Dec 28, 2020.

  1. Knosis_Co-Verse

    Knosis_Co-Verse

    Joined:
    Apr 23, 2019
    Posts:
    12
    Imagine I have 2 control schemes 1 for the character and other for the UI.

    When the player pauses the game the character controls are disabled.

    If the game is paused while the move input is pressed for exemple, the player will need to trigger it twice after exiting the pause menu.

    I imagine that happens because the key is released while the character controls are disabled.

    So is there a way of triggering the release action manually or resetting the input state? Or even keep listening the inputs without triggering the actions.

    Of course i could not disable the controls and check the game state manually, but that kind remove the power of having multiple schemes in my opinion.

    Sorry for the english, thanks.
     
    Last edited: Dec 28, 2020
  2. Knosis_Co-Verse

    Knosis_Co-Verse

    Joined:
    Apr 23, 2019
    Posts:
    12
    So, as far as my search go, it's not possible. To circumvent it, you need to add/remove the callbacks from the input actions which requires to keep an Action<CallbackContext> reference and keep the controls enabled all the time so they keep listening the inputs;

    It works, but a simple method to reset the input state would be nice, or a way to force the system to read the the current state of the input regardless of previous inputs.
     
    Last edited: Dec 29, 2020
  3. idbrii

    idbrii

    Joined:
    Aug 18, 2014
    Posts:
    51
    Are you calling Enable/Disable on the ActionAsset (the C# class generated by the input system)?

    I'm seeing the behaviour working as expected.

    Here's an example. I modified SimpleDemo from the input system's examples (see here for how to import). I added a "cycle" button that's bound to Space. I updated the Awake in SimpleController_UsingActionAsset.cs:

    Code (CSharp):
    1. void Awake()
    2. {
    3.     m_Controls = new SimpleControls();
    4.     m_Controls2 = new SimpleControls();
    5.  
    6.     m_Controls.gameplay.cycle.performed +=
    7.         ctx =>
    8.     {
    9.         m_Controls2.Enable();
    10.         m_Controls.Disable();
    11.     };
    12.  
    13.     m_Controls2.gameplay.cycle.performed +=
    14.         ctx =>
    15.     {
    16.         m_Controls.Enable();
    17.         m_Controls2.Disable();
    18.     };
    19.  
    20.     m_Controls.gameplay.fire.performed +=
    21.         ctx =>
    22.     {
    23.         if (ctx.interaction is SlowTapInteraction)
    24.         {
    25.             StartCoroutine(BurstFire((int)(ctx.duration * burstSpeed)));
    26.         }
    27.         else
    28.         {
    29.             Fire();
    30.         }
    31.         m_Charging = false;
    32.     };
    33.     m_Controls.gameplay.fire.started +=
    34.         ctx =>
    35.     {
    36.         if (ctx.interaction is SlowTapInteraction)
    37.             m_Charging = true;
    38.     };
    39.     m_Controls.gameplay.fire.canceled +=
    40.         ctx =>
    41.     {
    42.         m_Charging = false;
    43.     };
    44. }
    You can charge (left click) and then let go, you get the normal flurry of boxes.
    You can charge (left click) and then change input assets (space), your charge stops. I think that's the behaviour you're looking for.
     
  4. bodhi_berry

    bodhi_berry

    Joined:
    Feb 13, 2017
    Posts:
    8
    Hey, I'm having this same issue right now with a character controller.
    Did you ever find a simpler way of doing this? I see there is a Reset() function now in the input system but it doesn't seem to work.
     
  5. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
    You might try resetting the current input devices.