Skip to main content
Up and Coming
September 30, 2016

Universal menu integration

We are building a Rift game and found that we need to integrate it with the UM.

How can we know when the UM is active?

And how can we know if the user selected the Recenter App option?

Thanks
Andres
    This topic has been closed for replies.

    21 replies

    Inspiring
    September 30, 2016
    There isn't a way to know that the UM specifically is active, but you can detect the app has lost focus using OVRManager.hasVrFocus. You can detect that the app has been recentered by adding a handler to OVRDisplay.RecenteredPose
    baknoAuthor
    Up and Coming
    September 30, 2016
    Thank you
    Inspiring
    September 30, 2016
    Yes!!!! @vrdaveb !!!! I've been looking for this recenter option from universal menu for a long time!

    But, I can't find how to implement that from Unity, I've found:

    OVRManager.display.RecenteredPose, which is a System.Action that "Occurs when the head pose is reset"... But really don't know how to use it (I'm quite new to Unity).

    How can I "add a handler" to that????


    Inspiring
    September 30, 2016
    OVRManager.display.RecenteredPose += () => { /** Your code here. **/ };
    Inspiring
    October 1, 2016
    Thanks @vrdaveb, I've tried that code, and tried also with this syntax:
    OVRManager.display.RecenteredPose += delegate () { /** My code here. **/ };
    But I can't get the callback from the recenter option from the Universal menu. That seems to execute when I recenter the HMD from my own code, but not from the UM :(

    I'm starting to think I'm doing something really wrong, as this should work automatically in Unity, or be easy enough to be documented anywhere in the net, but... I can't find anything. And all Oculus programs I tried work well, but mine just doesn't do anything.

    Anyone knows what do you need to do in Unity to recenter the HMD when called from the oculus Universal Menu????

    Thanks!
    baknoAuthor
    Up and Coming
    October 4, 2016
    Calling OVRManager.hasVrFocus is always true. How do you integrate the OVR Plugin in Unity to make it work?

    We are using Unity 5.4 which is not supposed to need the OVR Plugin. But neither OnApplicationFocus or OnApplicationPause are called when the UM is activated or deactivated.
    Inspiring
    October 4, 2016
    > How do you integrate the OVR Plugin in Unity to make it work?

    OVRPlugin is an internal API that you should not be using directly.

    > I can't get the callback from the recenter option from the Universal menu.
    > neither OnApplicationFocus or OnApplicationPause are called when the UM is activated or deactivated.

    These both sound like bugs. We'll investigate and let you know if there is a fix or workaround soon.
    Inspiring
    October 4, 2016
    Have you enabled Run in Background in Player Settings? If not, please do.
    Inspiring
    October 4, 2016
    Hi @vrdaveb, and thanks!

    I didn't have that option enabled, I've enbled it and try... but nothing happens: from the app, I go to the Universal menu, select recenter, look and press "A", and it returns to the game, but no recentering at all :(

    Do I have to code something to make it work? I'm only binding the xbox back button to recenter the HMD manually with this:
    if (Input.GetButtonDown("Recenter"))
    {
        OVRManager.display.RecenterPose();
        Debug.Log("Recentering view... OK");
    }
    That works OK when I press the back button.

    In case it helps, I find it curious that when it comes back to the game after pressing A for recentering, it doesn't recenter, but I get the A button event and the game reacts to it (the player jumps!). Perhaps it shouldn't capture it?

    Thanks!

    Inspiring
    October 6, 2016
    I can't reproduce these issues. Can you try throwing this script onto a GameObject in your scene and sending me the output_log.txt?
    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;
    using System.Collections.Generic;

    public class EventTester : MonoBehaviour
    {
    public Text text;

    int logLength = 8;
    Queue<string> logBuffer = new Queue<string>();

    void Start()
    {
    OVRManager.HMDAcquired += () => Log("HMDAcquired");
    OVRManager.HMDLost += () => Log("HMDLost");
    OVRManager.HMDMounted += () => Log("HMDMounted");
    OVRManager.HMDUnmounted += () => Log("HMDUnmounted");
    OVRManager.VrFocusAcquired += () => Log("VrFocusAcquired");
    OVRManager.VrFocusLost += () => Log("VrFocusLost");
    OVRManager.AudioOutChanged += () => Log("AudioOutChanged");
    OVRManager.AudioInChanged += () => Log("AudioInChanged");
    OVRManager.TrackingAcquired += () => Log("TrackingAcquired");
    OVRManager.display.RecenteredPose += () => Log("RecenteredPose");
    }

    void OnApplicationQuit()
    {
    Log("OnApplicationQuit");
    }

    void OnApplicationPause()
    {
    Log("OnApplicationPause");
    }

    void Log(string message)
    {
    if (text != null) {
    logBuffer.Enqueue(message);
    while (logBuffer.Count > logLength)
    logBuffer.Dequeue();

    text.text = string.Join("\n", logBuffer.ToArray());
    }
    else
    {
    Debug.Log (message);
    }
    }
    }