- Home /
[VR] How to display a canvas with Oculus
Trying to make a crosshair follow the oculus using the canvas. Currently I'm using images on the canvas to draw the crosshair. I was originally using screen space- overlay and it was showing up in the unity editor but when the project was built it would not appear in Oculus. I also tried screen space - camera and it was appearing but it was far in the distance and hiding behind objects. I tried changing the plane distance but Unity would crash when I tried running it in the editor. Does anyone have any suggestions on how to make this work.
Answer by RicusMaximus · Jun 01, 2016 at 01:37 PM
Hey, I don't know if you're still struggling, but I found a solution for the UI with the Oculus.
Create a 2nd camera and make it a child of your main camera (CenterEyeAnchor if you use OVRCameraRig)
Set the Clear Flags on Depth only
Set the Culling Mask on Nothing first, then only enable UI
Make the depth 1 (or anything higher than your main camera)
This covers the camera, now you have to make the Canvas render in Screen Space - Camera Select the camera you just created, I call it UI camera, as the screen space renderer.
Now you have a transparent camera overlay with only UI elements that renders in the oculus.
I also want to add, the oculus renders the frustrum not as usual, you have to place your UI elements much closer to the center, but that is up to you.
thanks. at first i couldn't get it to work then i realized i had to replace my main camera with an OVRCameraRig available here https://developer3.oculus.com/blog/unitys-ui-system-in-vr/
also i planted a huge text button in the middle of the canvas so it was easy to see until i figure out where everything was
Will interaction be possible with the UI elements? Say, I need to use a button using controllers. Will it be possible?
I'm using HTC Vive. I believe the concept remains same whether its Vive or Oculus.
Thanks
Hi soorajkbabu, looking back on my answer here there's something very important which I didnt know at the time. If you stick a canvas to the camera in VR, this means it will move with the player's movement. For a normal HUD this is logical and preferred, in VR however, it's not. As of this moment there is no eye tracking software in the H$$anonymous$$D's, which means you can only focus on the center part of the screen, for the rest you have to turn your head. This means that, if you use the above solution, you will glue a canvas at a distance from someone's eyeball, never letting be able to focus on it. This can get really frustrating for users.
A better approach to this problem is to use canvases which are in world space and don't turn with the head of the player (unless it's a reticle or something)
Another point of attention is scaling. UI elements tend to stay the same size no matter the view. In VR this will result into the player not being able to focus if the world behind it is really small. For example if you have a reticle in the middle of the screen which doesn't change size, if you look very close at a wall in the VR space, you will not be able to focus on the reticle because it's in front of it due to the $$anonymous$$imal focal point of your eyes. Although they're being deceived, it's uncomfortable.
$$anonymous$$y solution (for now) is to have 2 sorts of UI elements, several that scale and several that don't. The non-scaling UI renders behind an extra 1m - 5m camera, so all UI elements are perceived to be at least 5m away. The UI elements that do scale, like the reticle, are raycasted to whatever object is in front of the player and adjusts it's position and scale to that, so it looks like it's in the VR space. This allows the player to keep focus on both objects.
It's a lot of trial and error, but the Unity Tutorial helps a lot too!
This method doesn't seem to be working for the VIV$$anonymous$$ I am using unity 5.6.3p2. Having a UICamera inside the CameraEye or the parent Camera Head and then a Canvas set to Screen Space - Camera and the UICamera selected does not seem to render anything. It's odd because, in the Display $$anonymous$$irror window of S$$anonymous$$m, you can see the UI element, but not when you have the headset on. Any solutions for how to get this to work on the VIVE? Essentially, I am trying to achieve the effect of having color show on the edges of the screen.
Good morning, I followed the steps and I have a problem, it is as if a lot of cameras are created, any idea why it could be?
Answer by SelfishReplicator · Nov 21, 2016 at 02:39 PM
This worked great for me. Thanks for your clear description!
Answer by unity_8AEPtfJUp3c0YA · Mar 20, 2019 at 12:52 PM
Awesome solution! Thank you @RicusMaximus :),Awesome solution. Thank you very much!
Answer by kirstyearley · Mar 25, 2019 at 10:40 AM
Thank you so much for this tip, @RicusMaximus :D It works brilliantly!