cancel
Showing results for 
Search instead for 
Did you mean: 

Oculus menu button press works locally but not when run on headset

foxvalleysoccer
Level 4

When I press the menu button on the oculus left controller my code doesn't detect the press when run on the headset. When i press play in unity the button press is detected.

This used to work in the older XR tool kit. I upgraded unity version and XRToolKit sdk. No errors when run locally.

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.Events;
using TMPro;

public class InputListenerSecondaryButton : MonoBehaviour
{
    public TextMeshProUGUI debuggertext;

    List<InputDevice> devices;
    public XRNode controllerNode;

    [Tooltip("Event when the button starts being pressed")]
    public UnityEvent OnPress;

    [Tooltip("Event when the button starts being released")]
    public UnityEvent OnRelease;

    //keep track of whether we are pressing the button
    bool isPressed = false;

    private void Awake()
    {
        devices = new List<InputDevice>();
    }

    void GetDevice()
    {
        InputDevices.GetDevicesAtXRNode(controllerNode, devices);
       
    }

    // Start is called before the first frame update
    void Start()
    {
        GetDevice();
    }

    // Update is called once per frame
    void Update()
    {
        GetDevice();
        foreach (var device in devices)
        {
           // Debug.Log(device.name + " " + device.characteristics);

            if (device.isValid)
            {
                bool inputValue;

                if (device.TryGetFeatureValue(CommonUsages.menuButton, out inputValue) && inputValue)
                {
                    if (!isPressed)
                    {
                        isPressed = true;
                   Debug.Log("OnPress event is called");
                        debuggertext.text = "Pressed button";
                        OnPress.Invoke();
                    }

                }
                else if (isPressed)
                {
                    isPressed = false;
                    OnRelease.Invoke();
                 Debug.Log("OnRelease event is called");
                    debuggertext.text = "OnRelease button";

                }
            }
            
        }
    }
}

 

0 REPLIES 0