How to call a method from a different class using Unity New Input System

*[Solved]*
I’ve been having some trouble wrapping my head around the new input system specifically with calling a method member of another class. When i attempt to call that method I get a MissingMethodException.

Here is an example of what I am getting:

public class Character_Actions:MonoBehaviour, Character_Input.IPlayerActions
{
    JumpingAction jump; // The class I am calling
    InputControls input; // My input map class
    public delegate void JumpButton( ); // delegate practice.
    JumpButton testButton;

void Awake()
{
    input= new InputControls ();
    input.Player.SetCallbacks(this);
    testButton = jump.GetComponent<JumpingAction>().Jump;
}

    public void OnEnable( )
    {
        input.Enable();

    }
    public void OnDisable( )
    {
        input.Disable();
    }

public void OnJump( InputAction.CallbackContext context )
    {
        if(context.performed) {
           testButton.Invoke
        }
    }

And then I have a jump function in a different class like:

public class JumpingAction: :MonoBehaviour
{
    Debug.Log(:I am jumping");
 
}

The method works but throws a MissingMethodException. What am I missing here?

Figured it out, found out that my Player Input component’s behavior was set to send message which would have search for type sting(i’m guessing). Changing it to Unity Events solved my issue. :slight_smile:

1 Like

Just keep reviewing the new input system and you’ll run into these kinds of issues less often, I’m going through the same thing, it’s a pretty powerful tool just got to wrap your head around it.

1 Like