Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Axis values do not persist scenes

Discussion in 'Input System' started by TheVastBernie, Jan 18, 2019.

  1. TheVastBernie

    TheVastBernie

    Joined:
    Mar 25, 2014
    Posts:
    10
    Hey, I'm trying to implement simple character movement. I created a horizontal movement action with an axis binding for my gamepad. On inputAction.performed I set my input value and in update I translate the player.

    That all works fine. However, whenever I reload the scene, or enter a new one the event is not called initially.
    Say, I'm moving right and then change into a second level/scene, while still holding right. There will not be a callback that a right press has been performed, meaning my player never knows that I am still holding right and thus doesn't move.

    I realize that performed is only called whenever the value of the gamepad actually changed (if it is at 1 for multiple frames the event is only called once), however this behavior seemingly makes it impossible for axis values to persist scenes without doing inelegant manual tracking of values.

    Is this an error on my end, do you have to access such values in a different way? Or is this a limitation of the system as it stands now?
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    I'm making some guesses here as to how specifically your setup works, but I assume that the problem you have will be resolved in the next package.

    Short answer: Actions are going to take existing control actuation into account. This should solve your problem. The changes are expected to hit in the next package.

    Long answer: There's a batch of changes coming up around this. Two changes in particular will likely make a difference for your use case.

    The more fundamental one is that actions will change to a different model when no interactions are involved. Right now, if you have a binding with no interactions on it, then it will call `performed` for every single value change. Going forward, this changes such that when the bound control starts being actuated, you first get `started` and then `performed`. And then for as long as the control changes value while actuated, you get a `performed` each time. Finally, when the control stops being actuated, you get a `cancelled`.

    On top, when enabled, actions will perform an initial control state check in the next update. In practice, this means that if a bound control was already actuated when you enabled the action, it will be as if the control was just actuated that very frame. In other words, going to a new scene when the user already holds a button down and calling Enable() on an action bound to that button will then trigger that action.

    Finally, for the cases where you want to trigger an action over and over while a control is actuated, you will be able to set actions to "continuous" mode which will run `performed` every update for as long as the control is actuated.
     
  3. TheVastBernie

    TheVastBernie

    Joined:
    Mar 25, 2014
    Posts:
    10
    Sorry for bumping this again, but I tried testing the behavior again with the newest version of the input system and it still seems to behave in weird ways. At this point I fear there is something I'm simply not getting.
    The broken down instance that is causing problems: I am constantly pressing right (Composite Axis binding using the Keyboard) and thus want the player to move right. When disabling the input action (but still pressing right) I want to stop the player and when enabling it again the player should start moving again. Now, when actually disabling the input action the player stops, as predicted. However what happens when re enabling the action is dependent on the Action Type. However the responses for the different types is fairly inconsistent and unintuitive (if there is no bug there...):
    • PassThrough: Input just doesn't work, even if enabled
    • Press: Action triggers on key down and key up (expected)
    • Value: Action triggers again when re-enabling the input action (as expected) but after a second disable and subsequent enable the action does not trigger anymore...
    I was using enabling/disabling of actions instead of changing the scene because the error is consistent in both setups. Again, am I missing something. This seems like pretty straight forward behavior that I'm not able to set up using the system...

    If you want to reproduce the error, here is a minimalist setup with a cube that can move left/right and a timer that enables/disables the input action: https://drive.google.com/open?id=16ccbCVnodPgPF8F2rZ6xfD2S-u6FraV6