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.

Question Button Press Stays in pressed state

Discussion in 'Input System' started by cuttinged, Jul 22, 2023.

  1. cuttinged


    May 12, 2013
    I'm converting my code from the old input system to the new input system and used the character controller from the Unity starter assets and how it is set up to convert to the new input system. A sample of the code is below, copied from StarterAssetsInputs.cs and it works to expose a public variable and control the input. It is visible in the editor so I can tell what is happening. The problem is, that sometimes the boolean for the button change doesn't change back to false, and stays true, and I'm not sure why.
    It references an input action which is set to "button" with a "press and release" binding for a gamepad.
    There are two action maps and maybe it gets stuck in the true position when it changes action maps but I can't tell for sure.
    It seems like this shouldn't matter anyways because it should do the button press and release in one frame and not be interrupted.
    Any ideas why it would not change back to false in the same frame? Or is there a better way to do this?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    5. using UnityEngine.InputSystem;
    6. using System.Collections;
    7. #endif
    9. namespace StarterAssets
    10. {
    12.     public class deleteme : MonoBehaviour
    13.     {
    14.         public bool pressm;
    16.         #if ENABLE_INPUT_SYSTEM
    18.         public void OnPressM(InputValue button)
    19.         {
    20.             //pressx=button.isPressed;
    21.             PressMInput(button.isPressed);
    22.         }
    24.         //More of the same like the above goes here.
    26.         #endif
    28.         public void PressMInput(bool newPressMState)
    29.         {
    30.             pressm = newPressMState;
    31.         }
    32.     }
    33. }
  2. cuttinged


    May 12, 2013
    This may be the same is it skips frame, but nevertheless it calls the button press more than one time and it's not related to started, performed, cancelled because I switched over everything to events and wrote the code for events and got it working in that way, and the same problem occurred, the button press registered more than one press no matter if the was set to interactions press only or press and release. Too bad Unity doesn't give developers help with this or at least put better comments on their code so it is easier to understand. As I can see in this forum there are so many unanswered questions, which shows that this system is very confusing to most people.