architecture
[Input System] Resolve ArgumentOutOfRangeException on Keyboard Key.None Access
Solution
Unity 2019.1.x - Unity 6.3.x
Published 26 days ago
An ArgumentOutOfRangeException is encountered when Keyboard.current is indexed using Key.None. This occurs because Key.None represents a logical placeholder for an unassigned state rather than a physical key index within the device's control array.
Quick-Fix
Directly indexing Keyboard.current with Key.None fails because it is an invalid control index for physical device polling.
using UnityEngine;
using UnityEngine.InputSystem;
public class KeyBindingValidator : MonoBehaviour
{
public Key userBinding = Key.None;
private void Update()
{
// Ensure target key is not Key.None before accessing the device array
if (userBinding != Key.None && Keyboard.current != null)
{
if (Keyboard.current[userBinding].wasPressedThisFrame)
{
Debug.Log("Valid input received.");
}
}
}
}
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
[Key Press] Stop Input.GetKeyDown Double TriggersPlayerInput Multi-Player Scheme Issue[Input System] Callbacks Not Firing
Content inspired by a Unity discussion post.