- Home /
How to build application for both VR and computer
I'm currently building an application that is to work in VR with an Oculus Rift, controlled by an Xbox controller.
I want the application made so that you don't need the VR in use for it to be seen and used on the monitor with the controller, as some people may have motion sickness or may not have a headset. I also would like a non-VR version of the application that doesn't need to work with VR support at all.
For me to be able to control it without using the headset, I've just been covering the sensor. For the version that can support VR, I've tried building it with Run in Background and Visible in Background on, through Player Settings, as well as changing it through the OVRManager script. Nothing has been working for me. In building the non-VR version, Unity doesn't let me turn off the Virtual Reality Supported button in the VR Settings under Player Settings.
Does anyone have any suggestions on how I can build either one of these versions?
Answer by mikewarren · Dec 10, 2018 at 06:25 PM
Unity has support to build for multiple XR devices, and it allows you to prioritize which device to use if it finds more than one. "None" is an acceptable XR device and can be added to list so that if no XR device is found, it will use "None".
You can force the device you wish to use through the "-vrmode" command line flag. See the following under "Built applications: Choosing startup device"
https://docs.unity3d.com/Manual/VROverview.html
In short, you can run the application with a -vrmode None flag and it will not run any VR device. Or, you can make None the default by putting it at the top of the XR support list and use the -vrmode flag to denote which device to use when you want to run on a system that supports XR.
The input device support for the XBox controller, or the Rift controllers is the same. So, you should be able to configure them through the input manager to the same name, and Unity will pick up either.
Good luck.
Mike
Thank you for your answer, $$anonymous$$ike! I managed to get a non-VR version of my application made. However the controls that were working in the Editor aren't working in the VR version and some of those that remained in the VR version are now not working in the non-VR version, so my control functionality is dropping as I build for different outputs. $$anonymous$$ight I be missing or misplacing something in my script for this to happen? Also from my understanding, the documentation linked through uses a prioritisation system to output one type of VR at a time, so no VR or the Oculus Rift. I would like to have both of them running at the same time, much like it does in Game $$anonymous$$ode of the Editor. Will I need to change the script to reflect this?
I can't really tell you why your controls aren't working, but I would endeavor to create one application that will both VR and non-VR depending on the vrmode command line flag. The following pages provide some information on accessing buttons and axes on a Xbox 360 and Rift Touch Controller.
https://docs.unity3d.com/$$anonymous$$anual/OculusControllers.html http://wiki.unity3d.com/index.php/Xbox360Controller
The default input manager is pretty poor. They only problem I've had is that the order and indexing of controllers may not be the same from machine to machine. For instance, one may only have Touch controllers and are indexed as joystick 0 and 1. Another may also have an XBox controller. If the XBox controller is joystick 0, the Touch controllers on that machine may be 1 and 2.
I would try to create a single app that can run in either VR mode or non-VR mode. When I run a Unity VR app, I still have an external window that displays the contents of the headset. Don't you?
Your mention of the Xbox and Touch controllers being on different joysticks made me double check my controls and I found out that some of the Xbox controllers were mapped under the joystick that the Touch controllers were on, so I managed to fix the controls. The joystick axis inputs found online were quite different from when I mapped them using the actual controller which was not consistent with Input $$anonymous$$anager. Thank you very much! When I run the VR app, it does have the external window, however I want to also use it without the H$$anonymous$$D on and have it continue running on the monitor. When I take off the H$$anonymous$$D, the screen blacks out like I've paused the game. I'll see what I can do in my script. Thanks again $$anonymous$$ike!