How to use Oculus Quest 2 X Y A B Keys in 2023?

As the title says. Could you provide me with a simplest examples there could be? I googled here and there and found nothing up-to-date. How do i make something happen in script once i press one of those buttons?
What i need precisely is switching between two diffrent skybox materials (mat1 assigned to button A and mat2 assigned to button B).

Thank you all in advance!

Assuming a script is a Singleton named XRInput, add the following content to it:

public bool XButton;
public Action XButtonDown;
public Action XButtonUp;

[SerializeField]
    InputActionProperty m_XButtonAction;
    public InputActionProperty XButtonAction
    {
        get => m_XButtonAction;
        set => SetInputActionProperty(ref m_XButtonAction, value);
    }


private void Awake()
    {
        XButtonAction.action.performed += p =>
        {
            XButton = true;
            XButtonDown?.Invoke();
        };
        XButtonAction.action.canceled += p =>
        {
            XButton = false;
            XButtonUp?.Invoke();
        };
}

open your XRI Default Input Actions


when you used:

//other script:
public void Start()
{
XRInput.instance.XButtonDown += () =>
{
    // your code
};
}

8993461--1238464--upload_2023-5-5_17-43-28.png
8993461--1238479--upload_2023-5-5_17-46-52.png

1 Like

Thank you for that answer @feathered_wing , that is a good answer for quick and easy implementation. There are a couple of other things that also might be helpful. If you plan to use OpenXR (and we highly recommend it from the Unity side), you should check out the more generic mappings against the XYAB buttons to provide a more cross-platform solution.

You can also check out the XRI Default Input Actions in the XR Interaction Toolkit > Starter Assets sample package. The combination of the XR Controller (Action-based) and the inputactions asset should be a good starting point.
8999734--1239868--upload_2023-5-8_9-54-16.png

If you want something even more straight-forward, the OpenXR package’s Controller sample package is another good starting point.
8999734--1239862--upload_2023-5-8_9-52-18.png