Unity-Technologies / XR-Interaction-Toolkit-Examples

This repository contains various examples to use with the XR Interaction Toolkit
Other
1.05k stars 347 forks source link

UserPresence not working as expected. #109

Open lejeanf opened 1 year ago

lejeanf commented 1 year ago

Hello.

I am trying to findout if the hmd is mounted or not. For this I use UserPresence Device binding:

/userPresence Here is the code I tried: ``` public class BroadcastHmdStatus : MonoBehaviour { public delegate void HmdStatus(bool status); public static HmdStatus hmdStatus; [SerializeField] private InputActionReference userPresenceInput; public static bool hmdCurrentState = false; [SerializeField] private bool userPresence = false; // just used as visual feedback in unity Editor [SerializeField] private bool isDebug = false; private void OnEnable() { userPresenceInput.action.Enable(); userPresenceInput.action.started += (ctx) => UpdateHmdState(true); userPresenceInput.action.canceled += (ctx) => UpdateHmdState(false); } private void OnDisable() => Unsubscribe(); private void OnDestroy() => Unsubscribe(); private void Unsubscribe() { userPresenceInput.action.started -= null; userPresenceInput.action.canceled -= null; userPresenceInput.action.Disable(); } private void UpdateHmdState(bool state) { if(isDebug) Debug.Log($"UserPresence: {state}"); hmdCurrentState = state; userPresence = state; hmdStatus?.Invoke(state); } } ``` In the console and in the EditorWindow I manage to get an update when the hmd is mounted on and was not on. But when I take it off it does not write anything to the console. When I mount it back though it writes that it was off and that its on now. It is like if the device is stopping sending data as soon as it is taken off, almost like its frozen and then send the data in the right order as soon as its back on. I use the Quest2 but I would like the code to work on any type of device. Oh and I run Unity 2021.3.15f1 LTS under windows11. OculusLiveLink works fine.