Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserPresence not working as expected. #109

Open
lejeanf opened this issue Apr 11, 2023 · 0 comments
Open

UserPresence not working as expected. #109

lejeanf opened this issue Apr 11, 2023 · 0 comments

Comments

@lejeanf
Copy link

lejeanf commented Apr 11, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant