Player Input component and Send Message using Interactions

Using the new Input system 1.0.0

I started out creating a c# script for the input system like I saw on some tutorials, and I got everything to work out great.

I later started looking at how I can have local multiplayer, and I found out that I need to use the Player Input component along with a Player Input Manager to get it done easily.

So now I have to go through converting my code to use it with the Player Input component.

The problem that I’m running into and can’t figure out is having the Player Input component use inputs with interactions (like “Hold”).

Here’s is my original code:

private void Awake()
        disqInputActions = new DisqInputActions();
        disqInputActions.Playercontrols.Move.performed += context => movementInput = context.ReadValue<float>();
        disqInputActions.Playercontrols.Jump.started += context => Jump(jumpHeight);
        disqInputActions.Playercontrols.Jump.canceled += context => CutJump();
        disqInputActions.Playercontrols.Dash.started += context => dash = dashMax;
        disqInputActions.Playercontrols.Dash.canceled += context => dash = 1f;
        disqInputActions.Playercontrols.Pound.started += context => { if (!airtime) disqAnimator.SetBool("Pound", true); };
        disqInputActions.Playercontrols.Pound.performed += context => disqAnimator.SetBool("Pound", false);
        disqInputActions.Playercontrols.Pound.canceled += context => disqAnimator.SetBool("Pound", false);
        disqInputActions.Playercontrols.Shoot.performed += context => disqAnimator.SetBool("Shoot", true);

To test the Player Input component, I wrote this code:


 public void OnMove()
        Debug.Log("Player moved.");

   public void OnJump()
        Debug.Log("Player jumped.");

    void OnDash()
        Debug.Log("Player dashed.");

    void OnPound()
        Debug.Log("Player pounded.");

    void OnShoot()
        Debug.Log("Player shot.");

    void OnAntigravityInputAction()
        Debug.Log("Player reduced gravity.");

The only debugs that come through are the Move and the Shoot functions, which are the only two Actions that do not use Interactions. Is it at all possible to use Player Input with interactions like “Hold”. Is there any way I can tell the function to look for “started”, “performed” and “canceled”?

I found out that my other functions worked only if I held the button long enough (for the Hold duration).
I ended up working around the problem by creating multiple Actions using the same binding with “Press only” and “Release only”.

hey i see this is sort of answered already but going thru this now i’d thought i’d add that if you have Player Input “Behavior” as Unity Events you could use Hold and the other Interaction types

using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Interactions;
  public void onButton(InputAction.CallbackContext value)
        if(value.interaction is HoldInteraction)

the documentation on the input system shows how to do the same thing with c# events so if you were using your older code you could check for interaction in side the event subscription.

disqInputActions.Playercontrols.Pound.started += context => { if(context.interaction is HoldInteraction doPound(); };