Im wanting to have both VR/Non-VR in game. And for my canvas raycasters to work right in each. (2020.3.23f1, URP)
This seems to work well enough as it is (XR Managemnet, VR in unity in general), except for one thing: Target Eye Mode + those raycasters.
In NON VR, if TargetEye on the main camera is set to ‘Both’ (the default), none of the raycasters work right. The UI shows on the left eye by default, and the raycasters hit … things, but nothing lines up with what you see.
If you manually switch the main camera targetEye (at runtime) to None, everything works. Suddenly the fov in player is large (90 deg, since that hasn’t changed) and the raycasters work as expected.
However I cannot find a way to change targetEye from a script.
When I do, it’s ignored. This is true if I’m trying to change it from Both → None (the “Im not in VR” scenario) and also if I change it manually to None (in editor), pop on a headset, and have the code try to change it from None → Both (the “Im in VR, honest!” mode).
Digging through the docs I also see a:
XRSettings.gameViewRenderMode
I’ve tried setting that as well, still no effect.
Is there a way to dynamically change the targetEye, at runtime?
If you do it manually, in the editor, while the game is running - it does work. So there’s gotta be a way… right?
private void SetupCamerasForVRAndNonVR(bool hmdEnabled)
{
var playerCamera = _worldUICoordinator.PlayerCamera();
if (!hmdEnabled)
{
XRSettings.gameViewRenderMode = GameViewRenderMode.None;
playerCamera.stereoTargetEye = StereoTargetEyeMask.None;
}
else
{
// main camera needs to be setup for both eyes.
XRSettings.gameViewRenderMode = GameViewRenderMode.BothEyes;
playerCamera.stereoTargetEye = StereoTargetEyeMask.Both;
}
}