cancel
Showing results for 
Search instead for 
Did you mean: 

How to display head-locked UI elements over eye buffer on Quest 2?

Shruggger
Explorer

I want to display small Unity UI elements to the player that can change dynamically. I at first tried to just use a canvas set to screen space but it didn't render to the screen. I tried to use the OVR Overlay except I can't figure out how to make it lock to the player's head. Are there any solutions to the problem I am trying to solve?

 

(Using Oculus Quest 2)

1 REPLY 1

turp182
Explorer

Here's what I do.

1.  Create a new GameObject, call it whatever it is (position 0,0,0).

2.  Inside that, create another GameObject, call it Offset for clarity (position this to where you want things in #3 to be as a group, see notes below).

3.  Put whatever you want to display in the Offset GameObject (position them relative to offset, they will keep the formation).

 

Then, add a script to the root GameObject with this in Update:

gameObject.transform.rotation = Camera.main.transform.rotation;

gameObject.transform.position = Camera.main.transform.position;

 

That keeps the root in the same place with respect to the camera view/rotation.

 

Then, use the Offset to position the entire group (#3 items).  The root position will update frame-by-frame, but the Offset will stay the same, so it can be used in run mode to adjust the position to you liking (otherwise you have to get an initial distance on Start and then and project the gameobject forward every frame, and the position changes every frame so you can't adjust the offset).

 

It should look something like this, here's my UI setup:

turp182_0-1647380355816.png