Difference between revisions of "Set up VR in Unity"

From Interaction Station Wiki
Jump to navigation Jump to search
 
(26 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
This tutorial covers Unity 2021.1 and Earlier
 +
 +
For Unity 2021.2 and Later please see this tutorial:
 +
'''[https://web.microsoftstream.com/video/c4ef83ef-8188-485d-bc02-2023e27a3504?list=studio | Unity VR and XR Interaction Toolkit 2021.2] ''' instead.<br/>
 
<br/>
 
<br/>
'''Setting up VR and XR interaction toolkit project in Unity for versions 2019.4,2020.x & 2021.1'''<br/>
+
To learn how to publish to the oculus Quest Standalone see here:<br/>
1. Install XR plugin management:
+
http://interactionstation.wdka.hro.nl/wiki/Unity_Tutorials_from_the_Interaction_Station#VR_with_the_Oculus_Quest
edit / project settings / xr plugin management / install xr pluging management
+
 
 
<br/>
 
<br/>
[[File:01_project_settings.png|size:600px]]
+
Download a basic template scene for 2021.2 and XR interaction toolkit here:<br/>
2. Add Oculus to the plugin providers:
+
https://hrnl-my.sharepoint.com/:u:/g/personal/pellm_hr_nl/EXi13fy_XUxAre1-HP6Ye98B9EjkV0nLwa0or1TC9eW2og?e=4UggFG
tick the Oclus box (if using oculus) open xr if using others
+
 
 
<br/>
 
<br/>
3.Enable preview Packages in the Package Manager
+
'''Setting up a VR and XR interaction toolkit project in Unity for versions 2019.4,2020.x & 2021.1'''<br/>
Window / Package Manager
+
 
in the package manager click on the gear and choose "advanced project settings"
+
This guide will show you how set up you Unity project to be visible inside a VR headset. The guide uses Unity's XR Plugin Management, with the XR Interaction Toolkit, and the OpenXR plugin. This will work on any desktop headset, but the guide assumes you're using an Oculus Quest headset.
under "Advanced Settings" tick on "Enable Preview Packages"
+
 
 +
In order to test this out on the computers at school, you'll need an Oculus Quest Headset, an Oculus Link usb cable (which is different from the Oculus charging cable), and the Oculus software installed on the computer. If the Oculus software doesn't open correctly you can find a fix [[About_Oculus_Quest#Fix_to_Enable_Oculus_Software_on_Student_Accounts|here]]. You'll need to have the Oculus software open and the link mode enabled in the headset.<br/>
 +
 
 +
 
 +
 
 +
'''1. Install XR plugin management:'''<br/>
 +
edit / project settings / xr plugin management / install xr pluging management<br/>
 +
 
 +
[[File:01_project_settings.png|200px]]<br/><br/>
 +
[[File:02_xr_plugin_management.png|400px]]<br/>
 
<br/>
 
<br/>
4.In the package Manager install "XR Interaction Toolkit *.*.*-pre*" (whatever the latest version is)
+
 
at the top left of the package manager select Packages: Unity Registry
+
'''2. Add Oculus to the plugin providers:'''<br/>
expand XR Interaction Toolkit and click see other versions
+
tick the Oclus box (if using oculus) or OpenXR if using any other headset <br/>
click install in the lower right corner of the package manager
+
OpenXR will work also with the Oculus on the desktop, but if you want to publish the Quest in standalone mode only the Oculus plugin will work. <br/>
 +
[[File:03_open_xr_plugin.png|400px]]<br/>
 +
Choose your PlayMode Open XR Runtime <br/>
 +
This will be Oculus, or Steam VR if you're using the Index or the Vive. <br/>
 +
[[File:04_open_xr_playmode.png|400px]]<br/>
 +
 
 +
'''3. Enable the Interaction Profile for Oculus:'''<br/>
 +
Or choose the profile that matches the headset you're using.<br/> 
 +
[[File:05_xr_interaction_profile.png|400px]]
 +
 
 +
'''4.Enable preview Packages in the Package Manager:'''<br/>
 +
Window / Package Manager<br/>
 +
[[File:07_xr_packagemanager.png|400px]]<br/>
 +
in the package manager click on the gear and choose "advanced project settings"<br/>
 +
under "Advanced Settings" tick on "Enable Preview Packages"<br/>
 +
 
 +
[[File:06_xr_advanced_package_settings.png|400px]]<br/>
 +
[[File:07_xr_enable_prerelease.png|400px]]<br/>
 
<br/>
 
<br/>
4B. In the XR interaction Toolkit package / samples
+
 
Download and import the Default Input Actions
+
 
 +
'''5.In the package Manager install "XR Interaction Toolkit":'''<br/>
 +
at the top left of the package manager select Packages: Unity Registry<br/>
 +
 
 +
[[File:08_xr_unity_registry.png|400px]]<br/>
 +
Find and select XR interaction Toolkit<br/>
 +
click install in the lower right corner of the package manager<br/>
 +
[[File:09_xr_xr_interactiontoolkit.png|400px]]
 
<br/>
 
<br/>
5. In the Project tab under assets
+
 
Assets / Samples /  XR interaction toolkit / 1.... / Default Input Actions /
+
'''5b. In the XR Interaction Toolkit Package samples, install the Default Input Actions:'''<br/>
select "XRI Default Left Controller" - In the inspector click "Add to ActionBasedController default"
+
Download and import the Default Input Actions<br/>
same for right
+
[[File:10_xr_samples_default_input_actions.png|400px]]<br/>
 +
 
 +
 
 +
 
 +
 
 +
'''6.Locate the Default Input Actions folder you've just imported:'''<br/>
 +
You'll find this in the Project tab under assets:<br/>
 +
Assets / Samples /  XR interaction toolkit / 1.*.*.*.* / Default Input Actions /<br/>
 +
[[File:11_xr_default_input_actions.png|400px]]<br/>
 +
[[File:12_xr_default_input_actions_pt2.png|400px]]<br/>
 +
select "XRI Default Left Controller" - In the inspector click "Add to ActionBasedController default"<br/>
 +
[[File:13_xr_default_input_actions_left.png|600px]]<br/>
 +
repeat the same for the right controller<br/>
 +
[[File:13_xr_default_input_actions_right.png|600px]]<br/>
 
<br/>
 
<br/>
6. edit / project / settings / preset manager /
+
 
under Action Based Controller in the filter add
+
'''7.Change the filter for the ActionBasedController in the Preset Manager:'''<br/>
"left" to the filter for "XRI Default left Controller"
+
edit / project settings <br/>
"right" to the filter for "XRI Default right Controller"
+
in the project settings window select "preset manager" <br/>
 +
under Action Based Controller in the filter add<br/>
 +
"left" to the filter for "XRI Default left Controller"<br/>
 +
"right" to the filter for "XRI Default right Controller"<br/>
 +
 
 +
[[File:14_xr_preset_manager.png|600px]]<br/>
 
<br/>
 
<br/>
7.now you can add an XR Rig - Action Based to your project
+
 
Game Object / XR / XR Rig Action Based
+
 
<br/>
+
 
8.On the XR rig Game Object in the inspector
+
'''8.now you can add an XR Rig - Action Based to your project:'''
add a component called
+
Game Object / XR / XR Rig Action Based<br/>
"Input Action Manager"
+
[[File:15_xr_xr_rig.png| 500px]]<br/>
 +
 
 +
 
 +
 
 +
'''8b.Add "Input Action Manager" to the XR rig:'''<br/>
 +
In the inspector for the "XR rig" Game Object , add a component called "Input Action Manager"<br/>
 +
[[File:16_xr_input_action_manager.png|600px]]<br/>
 +
 
 
in the component under "Action Assets" change the number to 1 and expand
 
in the component under "Action Assets" change the number to 1 and expand
 
click on the dot to select "XRI default input actions"<br/>
 
click on the dot to select "XRI default input actions"<br/>
9. You may have to enable the following setting: "Window/Analysis/Input Debugger/Options/Lock Input to Game View"
+
[[File:17_input_actions.png|600px]]<br/>
 +
[[File:17_input_actions_b.png|400px]]<br/>
 +
 
 +
 
 +
 
 +
'''9.Set the XR rig tracking origin mode to Floor:'''<br/>
 +
[[File:16_xr_rig_floor.png|400px]]<br/>
 +
 
 +
 
 +
 
 +
'''10.Lock input to game view:'''<br/>
 +
You may have to enable the following setting: "Window/Analysis/Input Debugger/Options/Lock Input to Game View"<br/>
 +
[[File:18_input_debugger.png|600px]]<br/>
 +
[[File:19_lock_input_to_game_view.png|600px]]<br/>
 +
 
 +
 
 +
 
 +
'''11.Enter playmode and put on the headset'''<br/>
 +
It should work now. Reflect on how annoying it is to follow all of these steps. It really should be simpler, shouldn't it?
 +
 
 +
 
 +
[[Category:Virtual Reality]][[Category:Unity]]

Latest revision as of 15:41, 21 November 2022

This tutorial covers Unity 2021.1 and Earlier

For Unity 2021.2 and Later please see this tutorial: | Unity VR and XR Interaction Toolkit 2021.2 instead.

To learn how to publish to the oculus Quest Standalone see here:
http://interactionstation.wdka.hro.nl/wiki/Unity_Tutorials_from_the_Interaction_Station#VR_with_the_Oculus_Quest


Download a basic template scene for 2021.2 and XR interaction toolkit here:
https://hrnl-my.sharepoint.com/:u:/g/personal/pellm_hr_nl/EXi13fy_XUxAre1-HP6Ye98B9EjkV0nLwa0or1TC9eW2og?e=4UggFG


Setting up a VR and XR interaction toolkit project in Unity for versions 2019.4,2020.x & 2021.1

This guide will show you how set up you Unity project to be visible inside a VR headset. The guide uses Unity's XR Plugin Management, with the XR Interaction Toolkit, and the OpenXR plugin. This will work on any desktop headset, but the guide assumes you're using an Oculus Quest headset.

In order to test this out on the computers at school, you'll need an Oculus Quest Headset, an Oculus Link usb cable (which is different from the Oculus charging cable), and the Oculus software installed on the computer. If the Oculus software doesn't open correctly you can find a fix here. You'll need to have the Oculus software open and the link mode enabled in the headset.


1. Install XR plugin management:
edit / project settings / xr plugin management / install xr pluging management

01 project settings.png

02 xr plugin management.png

2. Add Oculus to the plugin providers:
tick the Oclus box (if using oculus) or OpenXR if using any other headset
OpenXR will work also with the Oculus on the desktop, but if you want to publish the Quest in standalone mode only the Oculus plugin will work.
03 open xr plugin.png
Choose your PlayMode Open XR Runtime
This will be Oculus, or Steam VR if you're using the Index or the Vive.
04 open xr playmode.png

3. Enable the Interaction Profile for Oculus:
Or choose the profile that matches the headset you're using.
05 xr interaction profile.png

4.Enable preview Packages in the Package Manager:
Window / Package Manager
07 xr packagemanager.png
in the package manager click on the gear and choose "advanced project settings"
under "Advanced Settings" tick on "Enable Preview Packages"

06 xr advanced package settings.png
07 xr enable prerelease.png


5.In the package Manager install "XR Interaction Toolkit":
at the top left of the package manager select Packages: Unity Registry

08 xr unity registry.png
Find and select XR interaction Toolkit
click install in the lower right corner of the package manager
09 xr xr interactiontoolkit.png

5b. In the XR Interaction Toolkit Package samples, install the Default Input Actions:
Download and import the Default Input Actions
10 xr samples default input actions.png



6.Locate the Default Input Actions folder you've just imported:
You'll find this in the Project tab under assets:
Assets / Samples / XR interaction toolkit / 1.*.*.*.* / Default Input Actions /
11 xr default input actions.png
12 xr default input actions pt2.png
select "XRI Default Left Controller" - In the inspector click "Add to ActionBasedController default"
13 xr default input actions left.png
repeat the same for the right controller
13 xr default input actions right.png

7.Change the filter for the ActionBasedController in the Preset Manager:
edit / project settings
in the project settings window select "preset manager"
under Action Based Controller in the filter add
"left" to the filter for "XRI Default left Controller"
"right" to the filter for "XRI Default right Controller"

14 xr preset manager.png


8.now you can add an XR Rig - Action Based to your project: Game Object / XR / XR Rig Action Based
15 xr xr rig.png


8b.Add "Input Action Manager" to the XR rig:
In the inspector for the "XR rig" Game Object , add a component called "Input Action Manager"
16 xr input action manager.png

in the component under "Action Assets" change the number to 1 and expand click on the dot to select "XRI default input actions"
17 input actions.png
17 input actions b.png


9.Set the XR rig tracking origin mode to Floor:
16 xr rig floor.png


10.Lock input to game view:
You may have to enable the following setting: "Window/Analysis/Input Debugger/Options/Lock Input to Game View"
18 input debugger.png
19 lock input to game view.png


11.Enter playmode and put on the headset
It should work now. Reflect on how annoying it is to follow all of these steps. It really should be simpler, shouldn't it?