Unity (Gear VR) Getting Started
The Avatar Unity packages contain several prefabs you can drop into your existing Unity projects. This tutorial shows you how to start using them.
Download the Oculus Avatars SDK
The SDK is packaged in a .zip archive file on our developer website.
- Download the Oculus Avatars SDK .zip from https://developer.oculus.com/downloads/.
- If you do not have the Oculus Utilities for Unity 5, download its .zip file too.
- Extract the contents of the .zip archive files to your local drive.
Set Up Unity for Oculus Avatar Gear VR Development
The set up includes importing the Oculus Unity packages and also setting up Unity for Android development and debugging.
- Create a New Project in Unity named "gearvr-avatar".
- Click File > Build Settings and select Android. Download and install Unity Android Support and then restart Unity if necessary.
- Click Switch Platform to switch to Android platform.
- Click Add Open Scenes.
- Set Texture Compression to ASTC.
- Click Edit > Project Settings > Player, click the little Android Settings robot, and then set the following options:
- Select the Virtual Reality Supported check box.
- In Bundle Identifier, enter a unique package name.
- Set Minimum API Level to Android 5.0 'Lollipop' (API level 21).
- Set Install Location to Automatic.
- Import the Oculus Avatars (OvrAvatar.unityPackage) and Oculus Utilities (OculusUtilities.unitypackage) packages. For each package:
- Click Assets > Import Package > Custom Package.
- Select the package file from your local drive.
- Click All and then click Import.
- Connect your Android device to your computer.
- Create an Oculus Signature File for your Android device at https://dashboard.oculus.com/tools/osig-generator/and then copy it to the folder gearvr-avatar/Assets/Plugins/Android/assets. Create this folder if it doesn't exist.
Adding the VR Camera
Because the avatar has a default height of 170 cm, we should raise our VR camera rig to the same height.
- Delete Main Camera from your scene and then drag OVRCameraRig from OVR > PreFabs.
- Set the Position transform on OVRCameraRig to X:0,Y:1.70, Z:0.
Adding an Avatar
As the player cannot see his or her own Gear VR avatar, Gear VR avatars should all be of the "third person" type. To make sure the avatar is visible, we can place the avatar 50cm in front of the camera, and rotate the avatar 180 degrees so that its front faces us.
Note: The "local" in the prefab name "LocalAvatar" refers to how the avatar object gets its motion data. "Local" means the avatar object is driven by the local headset orientation.
- Drag OvrAvatar > Content > Prefabs > LocalAvatar to the Hierarchy window.
- In the Inspector, clear the Show First Person check box and select the Show Third Person check box.
- Select the Combine Meshes check box. This reduces total draw calls per frame per avatar to 6 from 22. Gear VR apps typically need to stay within 50 to 100 draw calls per frame.
- Set the Position transform on LocalAvatar to X:0, Y:0,Z:0.50.
- Set the Rotation transform on LocalAvatar to X:0, Y:180, Z:0.
- Click File > Build & Run to build an .apk from this scene and have Unity launch it on your Android device.
What to Explore Next?
Loading Personalized Avatars
See Unity Features for instructions on how to modify the sample scenes to retrieve Oculus User IDs and display personalized avatars.
Recording and Playing Back Avatar Pose Updates
Build our RemoteLoopback example scene and read the accompanying write-up in our Unity (Rift) Getting Started topic.