I have a game that users can play using VR (Oculus) or without VR (Desktop) both have their control schemes (Oculus, Desktop). I have a radial menu that takes input from Joystick in VR and Mouse Position on the Desktop.
When In VR I disable the mouse by calling InputSystem.DisableDevice(Mouse.current); after that, I receive input only from the VR controller joystick, but when HMD is removed and worn back I get input from the mouse: example ( vector2 (79.00, 347.00)) based on the mouse position. and after that, it no longer receives update/input from Joystick, it just gets stuck to that value from the mouse.
Input System 1.7.0;
Unity Version 2020.3.35f1;
OpenXR version: 1.4.2;
I have another question which is, when in VR I switch to the Oculus control scheme, but I still receive input from the keyboard or mouse, how to prevent input from the keyboard or mouse when the control scheme is switched to Oculus?
the solution I figured out is to disable the keyboard or mouse when using VR, but I am having the problem mentioned above,
if I remove the keyboard or mouse by calling InputSystem.RemoveDevice(Mouse.current); or keyboard.current. In the editor after play mode ends try to add them back using InputSystem.AddDevice doesn’t receive input from them although I can see them under devices in Input Debugger.
I don’t really understand, why would you remove them? Have you tried just simply Disable/Enable them as the manual states you should if you want to mute a device?
I did try using Enable/Disable, but as I mentioned after I called InputSysmte.DisableDevice(Mouse.current), if I remove my HMD and put it back, I will receive input from the mouse again.
Once I had something similar in a previous version, I thought they removed that behavior already. Anyway, I kept tab on devices like this, hope this helps or at least give you some ideas:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
#if UNITY_EDITOR
using UnityEditor;
#endif
public static class DeviceHandler
{
private static readonly Dictionary<InputDevice, bool> _shouldDisable = new();
#if UNITY_EDITOR
static DeviceHandler()
{
AssemblyReloadEvents.beforeAssemblyReload += Destructor;
}
private static void Destructor()
{
AssemblyReloadEvents.beforeAssemblyReload -= Destructor;
InputSystem.onDeviceChange -= OnDeviceChange;
}
#endif
public static void ToggleDevice(InputDevice inputDevice)
{
_shouldDisable.TryAdd(inputDevice, true);
_shouldDisable[inputDevice] = !_shouldDisable[inputDevice];
if (_shouldDisable[inputDevice])
{
InputSystem.DisableDevice(inputDevice);
InputSystem.onDeviceChange += OnDeviceChange;
}
else
{
InputSystem.EnableDevice(inputDevice);
InputSystem.onDeviceChange -= OnDeviceChange;
}
}
private static void OnDeviceChange(InputDevice inputDevice, InputDeviceChange deviceChange)
{
if (_shouldDisable.ContainsKey(inputDevice) && _shouldDisable[inputDevice]
&& deviceChange
is InputDeviceChange.Reconnected
or InputDeviceChange.Added) InputSystem.DisableDevice(inputDevice);
}
}
So I tried that, however it still doesn’t work.
The thing I noticed is when I disable the mouse using InputSystem.DisableDevice, remove my HMD, and wear it back, I don’t get any device changes from Mouse, but still I get a value from Mouse Position.