I’m using Unity 2022.2.16f1 (Input System 1.5.1) and keep encountering this error when trying to run my play mode tests (they ran fine on Unity 2021).
In my component, where “PlayerInput” is the class generated by my input actions:
private PlayerInput controls;
// ...
void Awake() {
controls = new PlayerInput();
controls.Character.Interact.performed += ctx => OnInteract();
controls.Character.Move.performed += StartMoving;
controls.Character.Move.canceled += (ctx) => _mover.StopMoving();
controls.Character.Run.performed += ctx => _mover.StartRunning();
controls.Character.Run.canceled += ctx => _mover.StopRunning();
}
void OnEnable() {
controls.Enable();
}
void OnDisable() {
controls.Disable();
}
In my test, which inherits InputTestFixture:
public override void Setup() {
base.Setup();
keyboard = InputSystem.AddDevice<Keyboard>();
playerObj = GameObject.Find("Player");
if (playerObj != null) {
// This is (a hacky?) way to get the player inputs
// to bind to the new keyboard input device
// (because it calls `controls.Enable()`).
var playerController = playerObj.GetComponent<PlayerController>();
playerController.enabled = false;
playerController.enabled = true;
}
}
IndexOutOfRangeException: Index was outside the bounds of the array.
UnityEngine.InputSystem.InputManager.AddStateChangeMonitor (UnityEngine.InputSystem.InputControl control, UnityEngine.InputSystem.LowLevel.IInputStateChangeMonitor monitor, System.Int64 monitorIndex, System.UInt32 groupIndex) (at ./Library/PackageCache/com.unity.inputsystem@1.5.1/InputSystem/InputManagerStateMonitors.cs:31)
From calling “controls.Enable()”.
Did something change in Unity 2022 about how the InputTestFixture works, or is this a bug?