I’ve gotten a new set of errors thrown when I plug in the first Controller. Plugging in a second Controller works as expected, but if I unplug Controller 2, the errors are thrown again. This has seemingly come out of the blue, and I haven’t fitzed with anything relating to the Inputs or Control systems in over a year.
ERROR 1:
ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index
UnityEngine.InputSystem.Utilities.ReadOnlyArray1[TValue].get_Item (System.Int32 index) (at Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Utilities/ReadOnlyArray.cs:152) ControlsManager.onInputDeviceChange (UnityEngine.InputSystem.InputDevice device) (at Assets/ControlsManager.cs:101) ControlsManager.<LateUpdate>b__32_0 (UnityEngine.InputSystem.InputDevice device, UnityEngine.InputSystem.InputDeviceChange change) (at Assets/ControlsManager.cs:321) UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue1,TValue2] (UnityEngine.InputSystem.Utilities.CallbackArray1[System.Action`2[TValue1,TValue2]]& callbacks, TValue1 argument1, TValue2 argument2, System.String callbackName, System.Object context) (at Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Utilities/DelegateHelpers.cs:71)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
ERROR 2:
ArgumentOutOfRangeException while executing ‘InputSystem.onDeviceChange’ callbacks
UnityEngine.InputSystem.LowLevel.NativeInputRuntime/<>c__DisplayClass7_0:<set_onUpdate>b__0 (UnityEngineInternal.Input.NativeInputUpdateType,UnityEngineInternal.Input.NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate (UnityEngineInternal.Input.NativeInputUpdateType,intptr)
ERROR 3:
ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: index
UnityEngine.InputSystem.Utilities.ReadOnlyArray1[TValue].get_Item (System.Int32 index) (at Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Utilities/ReadOnlyArray.cs:152) ControlsManager.onInputDeviceChange (UnityEngine.InputSystem.InputDevice device) (at Assets/ControlsManager.cs:101) ControlsManager.<LateUpdate>b__32_1 (UnityEngine.InputSystem.InputDevice device, UnityEngine.InputSystem.InputDeviceChange change) (at Assets/ControlsManager.cs:345) UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe[TValue1,TValue2] (UnityEngine.InputSystem.Utilities.CallbackArray1[System.Action`2[TValue1,TValue2]]& callbacks, TValue1 argument1, TValue2 argument2, System.String callbackName, System.Object context) (at Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Utilities/DelegateHelpers.cs:71)
UnityEngine.InputSystem.LowLevel.<>c__DisplayClass7_0:<set_onUpdate>b__0(NativeInputUpdateType, NativeInputEventBuffer*)
UnityEngineInternal.Input.NativeInputSystem:NotifyUpdate(NativeInputUpdateType, IntPtr)
Code for my ControlsManager:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Users;
using UnityEngine.InputSystem.Utilities;
public class ControlsManager : MonoBehaviour
{
public static ControlsManager controlMan { get; private set; }
public PlayerControlsTest controls;
public PlayerControlsTest controls2;
public PlayerInput playerInput;
public bool Accept_Pressed;
public bool Attack_Pressed;
public bool Ability1_Pressed;
public bool Ability2_Pressed;
public bool Use_Pressed;
public bool Beacon_Pressed;
public bool Grab_Pressed;
public bool Aim_Pressed;
public bool p2_Ability1_Pressed;
public bool p2_Ability2_Pressed;
public bool p2_Use_Pressed;
public bool p2_Beacon_Pressed;
public bool p2_Grab_Pressed;
public bool p2_Aim_Pressed;
public InputUser player;
public bool CoopEnabled = false;
public string currentControlScheme { get; }
//public PlayerInput playerControlsTest;
public void Awake()
{
controlMan = this;
CoopEnabled = false;
if (controls == null)
{
controls = new PlayerControlsTest();
controls.devices = new InputDevice[] {Keyboard.current, Mouse.current };
if(Gamepad.current!=null)
{
controls.devices = new InputDevice[] { Gamepad.all[0], Keyboard.current, Mouse.current };
}
}
else if (controls!=null)
{
controls.devices = new InputDevice[] { Keyboard.current, Mouse.current };
if (Gamepad.current != null)
{
controls.devices = new InputDevice[] { Gamepad.all[0], Keyboard.current, Mouse.current };
}
}
//print(Gamepad.all.Count);
if (controls2 == null)
{
controls2 = new PlayerControlsTest();
controls2.devices = new InputDevice[] {Keyboard.current, Mouse.current};
if (Gamepad.current != null && InputSystem.devices.Count>=4 && Gamepad.all.Count>=2)
{
controls2.devices = new InputDevice[] { Gamepad.all[1], Keyboard.current, Mouse.current }; // 2 was 1
}
}
BindingRefresh();
}
void onInputDeviceChange(InputDevice device)
{
if(device == Gamepad.all[0])
{
controls.devices = new InputDevice[] { Gamepad.all[0], Keyboard.current, Mouse.current };
Debug.Log("Mouse Keyboard)");
}
if (device == Gamepad.all[1])
{
controls2.devices = new InputDevice[] { Gamepad.all[1], Keyboard.current, Mouse.current };
Debug.Log("Gamepad");
}
else
{
Debug.Log("else return");
return;
}
}
public void BindingRefresh()
{
controls.Player.Attack.started += context => Attack_Pressed = true;
controls.Player.Attack.performed += context => Attack_Pressed = true;
controls.Player.Attack.canceled += context => Attack_Pressed = false;
controls.Player.Ability1.started += context => Ability1_Pressed = true;
controls.Player.Ability1.performed += context => Ability1_Pressed = true;
controls.Player.Ability1.canceled += context => Ability1_Pressed = false;
controls.Player.Ability2.started += context => Ability2_Pressed = true;
controls.Player.Ability2.performed += context => Ability2_Pressed = true;
controls.Player.Ability2.canceled += context => Ability2_Pressed = false;
controls.Player.Beacon.started += context => Beacon_Pressed = true;
controls.Player.Beacon.performed += context => Beacon_Pressed = true;
controls.Player.Beacon.canceled += context => Beacon_Pressed = false;
controls.Player.Use.started += context => Use_Pressed = true;
controls.Player.Use.performed += context => Use_Pressed = true;
controls.Player.Use.canceled += context => Use_Pressed = false;
controls.Player.Grab.started += context => Grab_Pressed = true;
controls.Player.Grab.performed += context => Grab_Pressed = true;
controls.Player.Grab.canceled += context => Grab_Pressed = false;
controls.Player.Aim.started += context => Aim_Pressed = true;
controls.Player.Aim.performed += context => Aim_Pressed = true;
controls.Player.Aim.canceled += context => Aim_Pressed = false;
controls.Player.Accept.started += context => Accept_Pressed = true;
controls.Player.Accept.performed += context => Accept_Pressed = true;
controls.Player.Accept.canceled += context => Accept_Pressed = false;
Beacon_Pressed = false;
Ability1_Pressed = false;
Ability2_Pressed = false;
Grab_Pressed = false;
Aim_Pressed = false;
#region Player 2
controls2.Player2.Ability1.started += context => p2_Ability1_Pressed = true;
controls2.Player2.Ability1.performed += context => p2_Ability1_Pressed = true;
controls2.Player2.Ability1.canceled += context => p2_Ability1_Pressed = false;
controls2.Player2.Ability2.started += context => p2_Ability2_Pressed = true;
controls2.Player2.Ability2.performed += context => p2_Ability2_Pressed = true;
controls2.Player2.Ability2.canceled += context => p2_Ability2_Pressed = false;
controls2.Player2.Beacon.started += context => p2_Beacon_Pressed = true;
controls2.Player2.Beacon.performed += context => p2_Beacon_Pressed = true;
controls2.Player2.Beacon.canceled += context => p2_Beacon_Pressed = false;
controls.Player2.Use.started += context => p2_Use_Pressed = true;
controls.Player2.Use.performed += context => p2_Use_Pressed = true;
controls.Player2.Use.canceled += context => p2_Use_Pressed = false;
controls2.Player2.Grab.started += context => p2_Grab_Pressed = true;
controls2.Player2.Grab.performed += context => p2_Grab_Pressed = true;
controls2.Player2.Grab.canceled += context => p2_Grab_Pressed = false;
controls2.Player2.Aim.started += context => p2_Aim_Pressed = true;
controls2.Player2.Aim.performed += context => p2_Aim_Pressed = true;
controls2.Player2.Aim.canceled += context => p2_Aim_Pressed = false;
p2_Beacon_Pressed = false;
p2_Ability1_Pressed = false;
p2_Ability2_Pressed = false;
p2_Grab_Pressed = false;
p2_Aim_Pressed = false;
#endregion
}
private void OnEnable()
{
controls.Enable();
controls2.Enable();
}
private void OnDisable()
{
controls.Disable();
controls2.Disable();
}
// This Chunk needs to be enabled and run only during setup phase..? Cant keep running.
void LateUpdate()
{
if (ControlsManager.controlMan.playerInput.currentControlScheme == "Gamepad")
{
if (Gamepad.current != null)
{
controls.devices = new InputDevice[] { Gamepad.all[0], Keyboard.current, Mouse.current };
}
}
if (ControlsManager.controlMan.playerInput.currentControlScheme != "Gamepad")
{
InputSystem.onDeviceChange +=
(device, change) =>
{
onInputDeviceChange(device);
switch (change)
{
case InputDeviceChange.Added:
Debug.Log("New controller" + device.description.serial);
break;
}
};
}
InputSystem.onDeviceChange +=
(device, change) =>
{
onInputDeviceChange(device);
switch (change)
{
case InputDeviceChange.Added:
break;
}
};
}
}
Specifically when I plug in Controller 1, I am expecting to see the Debug on line 104 called. Instead, it spits out Debug Line 99, “Mouse and Keyboard”, and then throws the previously referenced errors.
The game and controller input all function as expected, but I really want to eliminate these errors or understand why they’re occuring.
I thought it might have something to do with a drawing tablet which I previously didn’t have connected. When I plug this in, it throws : <RI.HUD> Failed to create device file: 2 The system cannot find the file specified.
This doesn’t concern me as much, as it won’t be used by players, but it’s also a small nag.
Any help is greatly appreciated!!!