How to properly use "Press And Release"?

I have a button action called “Fire”, bound to the Right Trigger.
I added a “Press” interaction to the Right Trigger binding under it, and chose “Press and Release” as the behavior.
5209049--518393--upload_2019-11-24_19-48-24.png

Then, based on the instructions in the tooltip, I set up my code like this:
5209049--518396--upload_2019-11-24_19-50-9.png

My idea being that when I release the trigger, it should call the StopFiring() method.
However, the “StopFiring” method seems to not be called at all, as the “Firing” boolean stays true and the Debug.Log is never printed to the screen.

1 Like

Got the same issue, this doesn’t behave as documented!

What it should do according to the doc/tooltip:
Perform action on button press, Cancel action on button release

What it does:
Perform action on button press, Perform action on button release

Using this to toggle a bool is fine for now, but I’m wondering if that’s intended behaviour.

5245460--523850--upload_2019-12-4_23-23-20.png
I too am looking forward to this feature of Unity, but somehow, I couldn’t get it to work either… This is what I do temporarily though… I created 2 Actions solely for a ButtonDown and a ButtonUp, I hope this gets resolved soon as well

1 Like

In the case above you can just inspect the phase of the action. Performed will be down and canceled will be up in a default button.

1 Like

You can simply watch for context.ReadValue (1 is pressed, 0 is released)

AFAIK, the ReadValue gets called only when the button is pressed (and when the button is released if that was enabled in the setting)… Now I think what we want is something like a charge function, where the ButtonDown would initiate the charge and the ButtonUp releases the charge… The problem is that wouldn’t some god-forsaken lag cause the controls to reverse their functions? Like once you initiate a charge, a lag spike occurs, as that happens you release the button, wouldn’t there be a chance that the ButtonUp event won’t register? If that happens, wouldn’t the next ButtonDown release the charge, and the next ButtonUp initiate the charge? This scenario would lead us wanting ButtonDown to have an exclusive function (initiate charge), as well as for ButtonUp (release the charge).


I’m not sure if I’m doing this right since I dove into it just recently, but I’ve never had the ReadValue go to anything other than “0”… I tried it both on Update and FixedUpdate but it never registered as “1”… Same goes for the phase, it just states “Waiting”… Canceled doesn’t seem to work either, from what I understand it only works with something like using Hold, and triggers when released prematurely… It shouldn’t work on Press since the press occurs once and immediately, and doesn’t have a fail-check?

Closest thing I can think of is to use Hold, set the Hold Time to “infinite” and wait for the “canceled” event to occur…

I’m probably missing a point somewhere…

EDIT: Just found out that having absolutely NO INTERACTIONS in the settings solved the problem of not detecting the “canceled” event…:face_with_spiral_eyes:

I confirm that the solution to use the Controller Triggers as buttons the way is to left blank the “INTERACTIONS” section.

But instead of using the “performed” event (which is called multiple times) it is necessary to use “started” and “canceled”.

        InputGame.Game.Switch.started += ctx => EventFunction_TriggerRight(true);
        InputGame.Game.Switch.canceled += ctx => EventFunction_TriggerRight(false);
2 Likes

DevBaro & Elledivar, y’all saved my life! I’ve spent hours today trying to figure this out (is this just a bug?) and clearing the Interactions just did it for me. I hope they fix/clarify this later in the documentation, because it sure is a lot more complicated than just using Input.GetButton (although in the long run it saves you a ton of time).

1 Like

Just an update for a simpler solution:

void Awake() {
    fireAction.performed += OnFire;
    fireAction.canceled += OnFire;
}

void OnFire(InputAction.CallbackContext context) {
    firing = context.performed;
}

So with the interaction set to “Press and Release”, checking with .performed and .cancelled on f.e. Right Mouse button, I got this log:
Action pressed
Action pressed
Action released

Notice there is an extraneous “pressed” phase in there that completely screwed me over for the past 1.5 hours.

Following this thread’s suggestion made in big red letters, removing the interaction setting, I get this log:
Action pressed
Action released

… meaning that this is definitely bugged on 2022.3.6f1.
Well, actually, I am guessing that this is the intended behavior and that both someone misunderstood the concept of a “canceled” input AND someone else forgot to update the documentation and tooltip.

Unbelievable. :face_with_spiral_eyes: