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.
Set Up the Unity Project for Oculus VR and Avatars
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.
- There are two ways to import the Oculus APIs into the Unity Editor. You can either:
- Navigate to the Oculus Integration page and select Import.
- In the Editor, select the Asset Store tab, Search for 'Oculus Integration', and select Import.
We recommend importing the complete integration package. This enables the core Oculus APIs, the Platform and Avatar APIs, and the Social Starter sample scene. Read about the Social Starter
, a sample scene that demonstrates how the Avatar and Platform APIs compliment each-other to create an engaging social experience.
- 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 must 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.
Add an Avatar with the Gear VR Controller:
In addition to the steps above, select the Start With Controllers check box in the Inspector. If a Gear VR Controller is connected as the main controller, the controller will be rendered in the scene with the corresponding hand animations.
What to Explore Next?
Loading Personalized Avatars
See Using 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.