cancel
Showing results for 
Search instead for 
Did you mean: 

Unity UnityEngine.XR.Recenter not working on Quest

chadstitch
Explorer
Hi all, I'm having a weird problem where I'm trying to call the 
Recenter

function. So I am currently trying to develop on the rift, and then building on the Quest. However, I am facing a problem, when I call the recenter function on the rift, everything works perfectly and as intended. However, when I test it on the Quest, the function does not seem to work at all. Does anyone have the same thing? 


If it matters, I'm using Unity 2018.4.0f1 LTS


Thanks all!

17 REPLIES 17

Batussai
Explorer
My solution to HandTracking recenter with Gesture Menu (RawButton.Start)

public static void RecenterHeadset()
    {
#if OCULUS_PLATFORM
        if (OVRManager.display != null)
        {
            float currentRotY = CameraManager.Main.transform.eulerAngles.y; //This refence a CenterEyeAnchor
            float difference = 0 - currentRotY;
            InteractionSystem.AnchorPlayer.Rotate(0, difference, 0); // InteractionSystem.Anchor This refence a Player

            Vector3 newPos = new Vector3(0 - CameraManager.Main.transform.position.x, 0, 0 - CameraManager.Main.transform.position.z);
            InteractionSystem.AnchorPlayer.transform.position += newPos;
        }
#endif
    }

5hmmqvccbx04.png


I hope it helps you 😉

larryPlayabl
Explorer
If you want to know when the user recenters their display, you can subscribe to:

OVRManager.display.RecenteredPose

It is reliably called each time the user triggers a recenter using Oculus Quest, after the camera has been repositioned. I don't believe it is invoked for Rift Reset View.

SergantTeddy
Explorer

if you dont mind the users still using the oculus home to reset orientation. you can also include your own code to be called when it is pressed by using this.
void Start()
{
           OVRManager.display.RecenteredPose += PlayerPressedOculusHome;
}
public void PlayerPressedOculusHome()
{
            Debug.Log("I Have Detected a headset Reset");
}

MrLeePerry
Honored Guest

Hey SergantTeddy!  That tip was awesome, and worked perfectly for what I needed, thanks so much!  I have a strange thing with it though, maybe you have some insight?

It works perfectly, the first time I do it... but subsequent resets of the orientation starts an explosion of errors though:

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
CocklpitBoundingMagic.PlayerPressedOculusHome () (at Assets/Scripts/CockpitModeStuff/CocklpitBoundingMagic.cs:47)
OVRDisplay.Update () (at Assets/Oculus/VR/Scripts/OVRDisplay.cs:125)
OVRManager.Update () (at Assets/Oculus/VR/Scripts/OVRManager.cs:1818)



SO... I assumed maybe this was a case of "I'm piggybanking off this OVRManager, but when I reset the view, that gets deleted or something, so my connection to the old one is now invalid".

I think there's some validity to that theory because I tried redoing the:
"OVRManager.display.RecenteredPose += PlayerPressedOculusHome;"
line every time I reset the view, and that fixes that error, presumably because it's resetting the connection to the newer element, but it only works as long as I have that script open and running forever in the project, haha.  Not great.

So yeah, any alternate or more stable ways to try and detect an orientation reset?  Thanks in advance if so 🙂

I wish those events would work! But for me, none of the two fire when re-centering the view on the Quest 2. Neither in stationary nor roomscale boundary.

Still struggeliing but and the other post no longer available 😕
What was the fix please ?
thanks

leozheng.2023
Explorer

I have the same problem when developing a game player can sit to play, so the head pose recenter is every useful when loading a new scene.

After digging more about those APIs, I found none of them works on my quest 2, so decide to recenter it by myself. The code is sample:

1. Record the FIRST head position and rotation.

2. Add a parent root for both head and hand gameobject, call it TrackingSpace.

3. Set the position (Quaternion.Inverse(FirstHeadRotation) * -FirstHeadPosition) and rotation Quaternion.Inverse(FirstHeadRotation) to TrackingSpace.

4. Then set head and hand position normally(directly from OVRInput or InputSystem).

 

In order to make height of head take effect, I set the Y axis of FirstHeadPosition to zero in step 3, so player could still put their head lower or higher.

 

Also, if player long press menu button from controller to reset the view, I also can't get called from RecenteredPose callback from SDK, but fortunately, I found OVRPlugin.GetLocalTrackingSpaceRecenterCount() will plus 1 every time I reset the view form controller, so I can check this to decide to record the latest position and rotation as FIRST head position and rotation, and then set them to TrackingSpace to finish the reset view inside game.

 

Hope those helps.

Very helpful and useful! Thanks for saving me a lot of time!