- Home /
Problem with new Input System Error when using interaction
Hello All. I am trying to fight the problem for two days but until now I was unable to find a solution. Here is the error which I am getting:
I am using new Input System. I have made all the steps according to the official guide. Here is my setup
And here is my code:
using UnityEngine;
using UnityEngine.InputSystem;
public class Movement : MonoBehaviour, Loco.IPlayerActions
{
InputAction pickup;
Loco controls;
private void OnEnable()
{
if (controls == null)
{
controls = new Loco();
controls.Player.SetCallbacks(this);
}
controls.Player.Enable();
pickup = controls.Player.PickUp;
pickup.started += _ => { Debug.Log("Started"); };
pickup.performed += _ => { Debug.Log("Performed"); };
}
public void OnMove(InputAction.CallbackContext context)
{
}
public void OnPickUp(InputAction.CallbackContext context)
{
}
private void OnDisable()
{
controls.Player.Disable();
}
}
Error appears only if I hold a button longer than given Hold time. Does anyone has any idea what is wrong?
Answer by aoikishu · Apr 25, 2020 at 12:56 AM
From my trial and error, I believe the parameter should be
CallbackContext when the Player Input's Behavior is set to "Invoke Unity Events"
InputValue when the behavior is "Broadcast/Send Messages".
Give this a try:
public void OnPickUp(InputValue value)
{
}
Answer by paulq · Mar 23, 2020 at 01:03 AM
Try removing or renaming your OnMove() and/or OnPickup() functions to something else. I had the same problem when trying to add functions named OnMove() and OnFire() to the "performed" InputActions for Move and Fire. Simply renaming them to OnMoveX() and OnFireX() had everything working as expected, although I don't know the reason for this.
Maybe someone else can give an explanation?
Might be because those function names are reserved in Unity. Good observation though, this fixed my problem!
The exact reason is that the callback function cannot be named "On[ActionName]" regardless of what the action name is. ie If you name your action "WeirdAction", then you cannot name the callback "OnWeirdAction".