XR Origin in Unity
Unity’s XR Origin represents you as the user in the VR realm. Let’s take a deeper look at the XR Origin and all that it has to offer.
Create an XR Origin
If you have already installed the XR Interaction Toolkit and Plugin Management, you can right-click and select the XR Origin from the XR drop-down menu.
An XR Origin is placed into the scene for you.
Here is what it looks like in the scene view.
Now we see the game view from the XR Origin perspective.
XR Origin Components
The XR Origin comes with a Camera Offset, as a reference to the head position, a main camera and controllers for each hand.
The XR Origin script component has references to the root game object, the camera offset, and the main camera.
The Tracking Origin Mode can be changed depending on your needs.
Device will set the view of the player to a set height, that you can adjust with the Camera Y Offset.
Floor mode will align the VR floor to the real-world according to the height of the user.
Input Action Manager
Being that the XR Toolkit uses the input system, the Input Action Manager is basically your VR input manager.
If you open up the XRI Default Input Actions, you can see the different user inputs from the headset being assigned to values like Position and Rotation. This is also where you can add or change inputs or create new actions. By default, the Input Action Manager enables all of the listed Action Maps when you run Unity.
Camera
The main camera has a few options setup to work with VR. The Target Eye is set to Both, because each eye has an independently rendered view.
The Tracked Pose Driver is used to update the camera position and rotation to say the least. You could change the Tracking Type to Rotation only, or Position only, to only update the camera for those values. The Actions for updating the Position and Rotation of the camera are by default set to the center eye position and device position Actions. So rather than using the input actions for the head tracking, the XR Origin is setup to read the actions directly through input bindings.
This is done so the XR Origin works out of the box without having to download the starter assets. I do want to use the input actions that came with the starter assets, so we can override the Tracked Pose Driver defaults by ticking the boxes next to Use Reference.
The last step is to assign the corresponding input action to the Reference slot.
XR Controller
The XR Controller has a lot of components, so let’s look at them one at a time.
The XR Controller component itself has a lot of references to different actions.
…and more…
You could painstakingly set everything up here manually, because it does indeed need to be setup to work, or you can let Unity to the heavy lifting for you to get started.
The starter assets come with presets for the head, left and right hand controller. Simply assign each preset to the corresponding hand, and you are ready to go!
Both right and left controllers should be ready to explore the VR environment.
That’s it for now, but I hope you join me in my next article where I cover the Ray Interactor. Happy VR development and thanks for reading!