Unity (Rift) Getting Started

The Avatar Unity package contains 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.

  1. Download the Oculus Avatars SDK .zip from
  2. If you do not have the Oculus Utilities for Unity 5, download its .zip file too.
  3. Extract the contents of the .zip archive files to your local drive.

Set Up Unity for Oculus Avatar Development

To set up, import the Oculus Unity packages into a project.

  1. Create a New Project in Unity named "Unity Avatar Demo Project".
  2. Import the Oculus Avatars (OvrAvatar.unityPackage) and Oculus Utilities (OculusUtilities.unitypackage) packages. For each package:
    1. Click Assets > Import Package > Custom Package.
    2. Select the package file from your local drive.
    3. Click All and then click Import.
  3. Select the Virtual Reality Supported check box in Edit > Project Settings > Player.
  4. Delete Main Camera from your scene and then drag OVRCameraRig from OVR > PreFabs.
  5. Reset the transform on OVRCameraRig.

Adding an Avatar to the Scene

The LocalAvatar prefab renders the player's avatar and hands. Check box options in the Inspector let you choose which parts of the avatar you want to render: body, hands, and Touch controllers.

To render avatar hands with controllers:

  1. Drag OvrAvatar > Content > Prefabs > LocalAvatar to the Hierarchy window.
  2. In the Inspector window, select the Start With Controllers check box.

Click Play to test. Experiment with the built-in hand poses and animations by playing with the Touch controllers.

To render avatar hands:
  1. In the Hierarchy window, select LocalAvatar.
  2. In the Inspector window, clear the Start With Controllers check box.

Click Play to test. Note how the finger joints transform to change hand poses as you squeeze and release the grips and triggers on the Touch controllers. You might sometimes want to use hand poses outside of these movements and we talk more about this in Custom Grip Poses.

To render the avatar body:
  1. In the Hierarchy window, select LocalAvatar.
  2. In the Inspector window, select the Show Third Person check box.
  3. Change Transform > Position to X:0 Y:0 Z:1.5
  4. Change Transform > Rotation to X:0 Y:180 Z:0

Recording and Playing Back Avatar Pose Updates

The avatar packet recording system saves avatar movement data as packets you can send across a network to play back on a remote system.

To see a demonstration, open the RemoteLoopback scene in OvrAvatar > Samples > RemoteLoopback.

Let us have a look at the RemoteLoopbackManager script.

Setting RecordPackets to true starts the avatar packet recording system. We also subscribe to the event handler PacketRecorded so that we can do something useful each time a packet is recorded.

void Start () {
    LocalAvatar.RecordPackets = true;
    LocalAvatar.PacketRecorded += OnLocalAvatarPacketRecorded;

Each time a packet is recorded, our code places the packet into a memory stream we are using as a stand-in for a real network layer.

void OnLocalAvatarPacketRecorded(object sender, args)
    using (MemoryStream outputStream = new MemoryStream())
        BinaryWriter writer = new BinaryWriter(outputStream);

The remainder of our code receives the packet from the memory stream and plays it back on our loopback avatar object.

void SendPacketData(byte[] data)

void ReceivePacketData(byte[] data)
    using (MemoryStream inputStream = new MemoryStream(data))
        BinaryReader reader = new BinaryReader(inputStream);
        int sequence = reader.ReadInt32();
        OvrAvatarPacket packet = OvrAvatarPacket.Read(inputStream);
        LoopbackAvatar.GetComponent<OvrAvatarRemoteDriver>().QueuePacket(sequence, packet);