0
votes

I am creating a basic 2D fighter game and am trying to replace what was the old input system with the new input system. Because of this the old systems update would wait for buttons and then call appropriate functions when they were pressed. Movement was actually the easiest part, simply rigging a 1D Vector and then grabbing the float to use with movement, awesome. However the difficulty is in pressing keys to change things in the game. For example, I have an input 's' which should lead to the method Crouch(). This method changes the animation running and alters the hitbox to be shorter and tell the attack to use a smaller hitbox as well. A Stand() method is called on release of 's' to return everything to the way it is. I have my Player Input object set to 'Invoke Unity Events' which leads to the corresponding method needed. The problem is that even though these events are set to be push and release they are read as a toggle effect instead of press and release triggers(respectively). This does the same thing with my attack function because it forces the animation to play twice, one for pressing and one for releasing. Is there a fix for this or is this currently a bug? Edit: Here are some images to clarify and the code used to reflect everything happening associated with the Attack functionality. Let me know if anything else should be needed

public void Attack(){
    anim.SetTrigger("attack");
    StartCoroutine(wait());
 }
IEnumerator wait(){
    if(!isCrouched){
        yield return new WaitForSeconds(1.3f);
        SHitBox.enabled = true;
        yield return new WaitForSeconds(.5f);
        SHitBox.enabled = false;
    }
    if(isCrouched){
        yield return new WaitForSeconds(1.3f);
        CHitBox.enabled = true;
        yield return new WaitForSeconds(.5f);
        CHitBox.enabled = false;
    }
 }

Binding Action

1
It's likely you just haven't set up your events or input mappings correctly. Could you provide some more info on how those are setup?Derek C.
I got everything updated, it seem that also running a basic debug.Log in my code shows that there are actually three calls to the method. My new guess is a call for the press, one for hold, and one for release. Hope that could also shed some light.AceOfSpades4654

1 Answers

0
votes

Think I figured it out. At least for the purposes of this specific thread. The answer was it was not my code. There is what I am going to call a bug in the new Unity Input System. Specifically there were three lines of code all simultaneously being hooked which caused three calls on my method. The fix was commenting out two lines of code. Here's the thread where this is solved, coincidentally found on GitHub help pages, heres the link: https://github.com/Unity-Technologies/InputSystem/issues/959 the issue is listed as close but its still a problem for me, lol... The only issue left is that the behavior of selecting the type of button press that I want to use is still acting funky. Mainly the inputs are still simply firing without listening to the type of input I want. I am basically just going to start searching through unity code to find where these choices have impact. If there are no comments/answers in 8 hours I'll accept my own answer because this has technically been answered, it just leads to another question.