Search Unity

Update polling

Discussion in 'Input System' started by Korindian, Jun 21, 2019.

  1. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    Hi, 3 questions:

    1. How do you do the equivalent for GetButtonDown, GetButton, and GetButtonUp in an Update method using an InputAction?

    2. According to the current "How Do I" section of the docs, in the fireAction example, an InputAction has a hasBeenPerformedThisFrame, but I'm not able to access it. Has this been removed?

    3. When using events, all the examples show event subscription using lambdas, and enabling and disabling actions. I'm assuming we need to unsubscribe also, or is that not needed when using lambdas?
     
  2. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    Did a lot more testing, forum searches, etc. Hope someone can correct me if the following is wrong:

    1. According to this post, to get the equivalent functionality of the GetButton methods of the old input system, leave "interactions" blank, and check "continuous" for the InputAction. This will have "started" and "performed" events fired on pressing the button (the equivalent of GetButtonDown), "performed" fired as long as the button is held down (GetButton), and "canceled" fired when the button is released (GetButtonUp).

    There is no equivalent to a bool for started, performed, or canceled on the InputAction which simply lets us do a check like:

    if (Input.GetButton("SomeButton")
    {
    // Code here.
    }

    like in the old system. We currently have to have another layer of abstraction by assigning bools when handling the events, and setting these bools to false every frame after the logic is done. This extra work should be unnecessary, but I guess with all the different types of interactions on the InputAction that can fire the started/performed/canceled events at different times, perhaps this makes sense? It's a little convoluted.

    2. As mentioned above, seems like these bools have been removed, adding another layer of complexity.

    3. Edit: My original answer was wrong. It's difficult to unsubscribe from an anonymous method, and thus we'd need a reference. It's safer to just subscribe/unsubscribe to a regular method. Enable()/Disable() has nothing to do with event subscription I believe.
     
    Last edited: Jun 21, 2019
  3. Elhimp

    Elhimp

    Joined:
    Jan 6, 2013
    Posts:
    75
    You still have things like
    Keyboard.current.digit3Key.wasPressedThisFrame

    But the whole idea is to get rid of pull-notifications and instead push 'em.
     
    Korindian likes this.
  4. Ofx360

    Ofx360

    Joined:
    Apr 30, 2013
    Posts:
    155
    Yeah Korindian, for now it seems like you're forced to use callbacks if you want to use InputActions.

    Just like you're saying, i had to setup an abstraction layer to get polling.

    I really hope a polling option is added in the future
     
    PereKastor and Korindian like this.
  5. Korindian

    Korindian

    Joined:
    Jun 25, 2013
    Posts:
    584
    Apparently a polling API is in the works. Great! Found this Github Issue.

    I also agree with the last post in the link. It would be wonderful if for InputActions we could get the same API as Keyboard.current input bools:

    wasPressedThisFrame
    wasReleasedThisFrame
    isPressed

    This would allow us to get rid of a lot of extra code. @Rene-Damm
     
    Last edited: Jun 28, 2019
    Xavierseal, Ofx360 and PereKastor like this.