Hello, I have two problems when it comes to testing out the new input system. I have a super simple WASD control scheme set up like so: This is my code ("Input" is the auto-generated class): Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; public class newInputSystemTests : MonoBehaviour { public Input input; void Awake() { input.Player.Move.performed += ctx => LogOnConsole(ctx.ReadValue<Vector2>()); } void LogOnConsole(Vector2 value) { Debug.Log("keyboard: " + value); } } Every keypress apparently is logging twice (on press, not on press and again on release), and also an exception happens in between, every time: Any ideas? Thanks for taking the time, I'm using this for the first time today and I'm taking it step by step.
I think you must enable the controls first to be able to use them. I. e. add something like this: Code (csharp): void OnEnable() => input?.Player.Enable(); void OnDisable() => input?.Player.Disable(); I'm pretty new to this, too, but I'm not sure whether "Key" action type is the right one to use here. I'd probably leave it on "Any" and see if anything changes. Also for movement, you'll probably want to use Continuous action (= trigger all the time while you hold a button) instead of Hold (= trigger once if you hold a button long enough). If it doesn't help, you could also try the "Generate Interfaces" approach and have something like this: Code (CSharp): using UnityEngine; public class NewInputSystemTests : MonoBehaviour, IPlayerActions { [SerializeField] Input input = default; void Awake() { input?.Player.SetCallbacks(this); } void OnEnable() => controls?.Player.Enable(); void OnDisable() => controls?.Player.Disable(); public void OnMovement(InputAction.CallbackContext context) { if (context.performed) { Debug.Log($"Keyboard: {context.ReadValue<Vector2>()}"); } } }
I should have pointed out that I enable the controls elsewhere. In fact, you can see them working: they do log the correct XY Vector2 in response to a keypress. I've solved this, but frankly I am completely unsure how it happened and I think this could be a bug. All I've done was remove the default Interaction for the action (it had a Hold interaction, added by default) and check and uncheck the "Continuous" checkmark. It works correctly now: no duplicate input, no exception between the duplicate inputs. Very strange. Thanks for the contributions, @Rallix.
The duplicate triggering was the original default behavior that has since been changed. Basically, actions used to trigger on any single value change if there was no interaction added to a binding. So, one trigger on button down, one on button up. The default behavior has since been changed to trigger 'performed' only when a control starts being actuated (e.g. button goes down) and trigger 'cancelled' when a control is being released. The old behavior can be restored by toggling "Pass-Through" on.