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.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Gamepad joystick movement question

Discussion in 'Input System' started by Luminoth, Jul 27, 2018.

  1. Luminoth

    Luminoth

    Joined:
    Jan 15, 2013
    Posts:
    25
    Hi, I'm trying to get move/look actions working on a Gamepad and I have my Controls.inputaction with a move action added on the Gamepad leftStick, but for some reason while I can bind to the action.performed event and it comes in fine, if I bind to the action.cancelled event, I never receive it. This is causing an issue for me because it's sometimes hard to tell when the player let go of the stick (since the performed event only seems to fire when the joystick value changes).

    Is there some better way to do this? I've tried changing the move binding to also use the Hold modifier but that seems to not trigger any of the events.
     
  2. Luminoth

    Luminoth

    Joined:
    Jan 15, 2013
    Posts:
    25
    It seems like I don't get the started/cancelled events also if I do like "Press Gamepad buttonEast" and so on. Are those events just not hooked up to do anything or is there an extra step to get them going?
     
  3. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    To explain a little, phase transitions on an action are primarily driven from interactions. If there's no interaction on an action, "performed" is the only thing that you will see. The action will simply trigger "performed" every time a bound control changes state (meaning also when it goes back to its default value) and then will go back to waiting. If one or more interactions are present, then the phase transitions are entirely driven by them.

    I don't think we have an interaction out-of-box ATM that does exactly what you want for the stick. The ones that are in there so far are pretty much all focused on button interactions and mostly won't have very useful behavior on a stick.

    The Press interaction indeed only triggers Performed. PressAndRelease triggers Started and Performed.

    One way would be to do this manually in the performed callback by storing the last value. If the last value is non-zero and the current value is zero, the stick has gone back to its deadzone.

    Ideally, there should be an interaction for this. Will have a look.
     
  4. Luminoth

    Luminoth

    Joined:
    Jan 15, 2013
    Posts:
    25
    Ok, that makes sense. I think for now what makes most sense for me is to just call ReadValue() on the stick(s), tho I am curious about something else coming out of that. Right now I have to do something like Gamepad.leftStick.ReadValue(), which assumes leftStick is say, movement. What I don't see is a way to do Controls.actions.move.ReadValue(). Is there no way to call ReadValue() through the InputAction? I thought I saw in the documentation that you could do that, but the method doesn't seem to be there.
     
  5. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    You can do a read value in the callback like so:

    Code (CSharp):
    1. myAction.performed +=
    2.     ctx =>
    3.     {
    4.         var value = ctx.ReadValue<Vector2>();
    5.         //...
    6.     }
    This will read a 2D vector from the control that triggered the action. Will also work if, say, you've bound a WASD key combination to the move.

    I'm looking at adding a "StickInteraction" that would give you a "started" when the stick goes out of its deadzone, a "performed" while the stick moves around outside the deadzone, and a "cancelled" when the stick moves back into the deadzone. Something like that.
     
  6. Luminoth

    Luminoth

    Joined:
    Jan 15, 2013
    Posts:
    25
    Sweet, that would actually be perfect then, thank you!

    Also, I really, really enjoy working with this new system. It is so many leaps and bounds better than the old input manager.
     
  7. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Took a stab at it here: https://github.com/Unity-Technologies/InputSystem/commit/430b36e2f603cf32ed6cce6ca1b35003264dbe92. Putting this on a stick binding should give you the behavior of started/performed/cancelled when the user starts moving the stick and then lets it go.

    That's great to hear :) Especially at this still relatively early point.

    The action portion of the system is still pretty rough and has a lot of holes but hopefully within the next 3-4 months, we'll see some great progress there. Other than that, barring any surprise findings, I think the system just needs a lot of stabilization and a couple features here and there (plus of course plenty of docs) and then we should be good to go.
     
  8. Luminoth

    Luminoth

    Joined:
    Jan 15, 2013
    Posts:
    25
    So I tried out that update and it seems like the cancelled is getting called at times that it shouldn't. In other words it's getting called while I'm still moving the stick.
     
  9. Luminoth

    Luminoth

    Joined:
    Jan 15, 2013
    Posts:
    25
    So it seems like after grabbing that update, in order to save changes to my controls asset, I have to click Save and then focus a window other than Unity and then back to Unity. Otherwise I lose my changes when I close the asset editor.
     
    Last edited: Jul 28, 2018