Search Unity

Getting Key Up/Down with default SendMessages Behavior

Discussion in 'Input System' started by tacman1123, May 17, 2022.

  1. tacman1123

    tacman1123

    Joined:
    Sep 14, 2020
    Posts:
    77
    I'm struggling with how to detect KeyPressed and KeyUp in the new input system without rewriting the script to handle Unity or C# events.

    That is, OnJump (the spacebar) works as expected with no interactions.

    public void OnJump()
    {
    Debug.Log("OnJump");
    }

    But I'm trying to respond to both the press and release events, so I set up the interactions:

    upload_2022-5-17_7-22-22.png

    Is there an event name, like OnJumpPressed/Canceled that I could respond to?

    I tried following the suggestions elsewhere and

    Code (CSharp):
    1. //Callback for "Space" button
    2. public void OnJump(InputAction.CallbackContext context)
    3. {
    4.    if (context.started)
    5.    {
    6.       Debug.Log("started");
    7.       //button is press
    8.    }
    9.    else if (context.performed)
    10.    {
    11.       Debug.Log("performed");
    12.    
    13.    }
    14.    else if (context.canceled)
    15.    {
    16.       Debug.Log("canceled");
    17.       //button is released
    18.    }
    19. }
    Even changing the behavior didn't work:

    upload_2022-5-17_7-38-29.png

    MissingMethodException: Method 'Player.OnJump' not found.
    System.RuntimeType.InvokeMember (System.String name, System.Reflection.BindingFlags bindingFlags, System.Reflection.Binder binder, System.Object target, System.Object[] providedArgs, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, System.String[] namedParams) (at <8516445456524a6cb20c4b3b7de67982>:0)
    UnityEngine.SetupCoroutine.InvokeMember (System.Object behaviour, System.String name, System.Object variable) (at /home/bokken/buildslave/unity/build/Runtime/Export/Scripting/Coroutines.cs:30)
    UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
    UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr) (at /home/bokken/buildslave/unity/build/Modules/Input/Private/Input.cs:120)


    but I don't really want to change the behavior anyway, because everything else already works. I just want to be able to respond to key up and key pressed events.

    The new Input System is so much more powerful than the old manager, but I'm stuck on what seems to be something simple.

    Thanks.
     
    Last edited: May 17, 2022