Call Jump into PlayerController script -> CS0407 Error

Hello all,

I am trying to read my Jump into the PlayerController script from my GameInput script. The only thing that is not recognised is the return value from the new Unity input system. The animator is in the PlayerController script. That is why I only write in the PlayerController Update that I have received it.

Could you help me?

GameInput Script:

public class GameInput : MonoBehaviour
{
    private PlayerInputActions playerInputActions;
    private Rigidbody rb;
    [SerializeField] private float jumpAmount = 7;

    private void Awake()
    {
        playerInputActions = new PlayerInputActions();
        rb = GameObject.Find("PlayerCanvas").GetComponent<Rigidbody>();
        playerInputActions.Player.Enable();
        playerInputActions.Player.Jump.performed += Jump_performed;

    }

    public float Jump_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
    {
        rb.AddForce(Vector2.up * jumpAmount, ForceMode.Impulse);
        float inputFloat = playerInputActions.Player.Jump.ReadValue<float>();
        return inputFloat;
    }

Thank you :slight_smile: Greetings, Nico.

8930538--1224159--button_space.PNG

What’s the error?

Always provide the full error text. Nobody remembers the error codes.

Anyway, CS0407 means that you tried to assign a method to an incompatible delegate type. The input system expects you to provide a function that takes one argument (the context) and returns void. You are giving it a function that takes one argument (the context) and returns a float.

These are incompatible. Make the function return void (and don’t return anything from it) and it ought to work fine.

If you want to save that float value for later use, you could assign it to a variable on the GameInput class.

1 Like

Hi guys,
Sorry I missed the error message. But thank you for giving me feedback anyway :slight_smile: You’re right. I changed the function to a void funtion and it works. Thank you very much.