New Input System: Hold interaction called only once
I created an InputController with a small jump action (Tap interaction, max 0.15) and a big jump action (Hold interaction, min 0.16)
I properly created my inputController class and registered to the 2 events in awake (also added the onEnable and onDisable):
inputController.ControlMgr.Jump.performed += SmallJump;
inputController.ControlMgr.HighJump.performed += HighJump;
Here is the code of the event handlers:
///
/// Small jump. Triggers feedbacks that rotates the cube
/// </summary>
/// <param name="ctx"></param>
public void SmallJump(InputAction.CallbackContext ctx)
{
if (!_jumping && ctx.performed)
{
_rigidbody.AddForce(Vector3.up * JumpForce, ForceMode.Impulse);
_jumping = true;
JumpFeedback?.PlayFeedbacks();
}
}
/// <summary>
/// High jump. Triggers feedbacks that rotates the cube
/// </summary>
/// <param name="ctx"></param>
public void HighJump(InputAction.CallbackContext ctx)
{
Debug.Log("HighJump " + ctx.phase);
if (!_jumping && ctx.performed)
{
_rigidbody.AddForce(Vector3.up * (JumpForce + HighJumpExtra), ForceMode.Impulse);
_jumping = true;
JumpFeedback?.PlayFeedbacks();
}
}
My issue is that the HighJump is called once (I see my log once), then it's not called anymore. I have the exact same actions for my move (a smallMove "tap" and bigMove "hold") on a 1d axis and it works correctly there, but not for my jumps, I have no idea why.
Answer by MastaMax · Oct 11, 2021 at 06:47 AM
In case anyone has the same issue. Here is how I fixed it:
I changed the action type from Button to "Pass Through" with control type "Button".
I'm not sure why this fixed it, but here is the documentation:
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Actions.html
Value
This is the default Action type. Use this for any inputs which should track continuous changes to the state of a Control.
Value type actions continuously monitor all the Controls which are bound to the Action, and then choose the one which is the most actuated to be the Control driving the Action, and report the values from that Control in callbacks, triggered whenever the value changes. If a different bound Control actuated more, then that Control becomes the Control driving the Action, and the Action starts reporting values from that Control. This process is called disambiguation. This is useful if you want to allow different Controls to control an Action in the game, but only take input from one Control at the same time.
When the Action initially enables, it performs an initial state check of all bound Controls. If any of them is actuated, the Action then triggers a callback with the current value.
Button
This is very similar to Value, but Button type Actions can only be bound to ButtonControl Controls, and don't perform an initial state check like Value Actions do (see the Value section above). Use this for inputs that trigger an Action once every time they are pressed. The initial state check is usually not useful in such cases,because it can trigger actions if the button is still held down from a previous press when the Action was enabled.
Pass-Through
Pass-Through Actions bypass the disambiguation process described above for Value Actions and don't use the concept of a specific Control driving the Action. Instead, any change to any bound Control triggers a callback with that Control's value. This is useful if you want to process all input from a set of Controls.