I thought I might be missing something as this seems a basic thing, but I keep testing and finding it not working.
I’m using Unity 2020.1.6.f14510. Input System has no update since April according to my package manager? Weird considering how fast bug fixes were coming before, but no matter.
Anyway, I’m just dealing with simple button stuff here. This happens on both keyboard & gamepad (and I’d wager anything). Just 1 player for this case, if it matters, Auto-Switch is on, default scheme is Any. I’m using Invoke Unity Events.
So, any which way here, my action gets triggered on both the Press AND Release of my button. I thought press only was default, but just to make sure, I added the interaction Press Only explicitly, but same issue.
I tried debugging a little, and on the press, my function gets triggered twice, once for started and once for performed. On release of my button, it gets triggered again (herein lies the error, I think), and then the phase is cancelled. I got around it with this:
public void OnAttack (InputAction.CallbackContext context)
{
//UnityEngine.Debug.Log(context.interaction);
//UnityEngine.Debug.Log(context.phase);
// Avoid doing this on the RELEASE of the button
if (context.phase != InputActionPhase.Canceled)
animator.SetBool("attacking", true);
}
…but shouldn’t have to do that, right?