Custom Avatars

Paul Molnar, May 2022

Overview:

This page will go into detail about how to set up a custom avatar in Photon Pun 2. Maybe you're developing a VR application where you want your avatar to have hands and a head that move with the headset and controllers or maybe you just want something in sync with your character rig. Either way there are options for both and many different character styles you can create using Unity. This tutorial will explain how to set up your Photon Pun 2 components so that your avatars follow different components and will sync across each players screen to create a synchronized experience.

Set Up:

If you haven't already, go set up a basic multiplayer VR project by either going to this page in the wiki: Tutorial: Steam VR in Unity with Photon Pun 2 , or by watching the following three YouTube videos made by Valem: Video 1, Video 2, Video 3. The difference between the web page and the three videos is that the webpage sets up your project to use Steam VR instead of a classic Unity XR project. Both are similar but also have some important differences. Take a look on the webpage link to see why you might want to use Steam VR.

After completing either of the tutorials you will already have a basic avatar. There will be a head that follows the headset position, and two hands that follow each of the hand controllers. Make sure if you do the video tutorials to go all of the way to video 3 so that you fix all of the bugs he makes along the way. From here extending this to be a custom avatar is not very hard. Below are two images of avatars created from this same tutorial. This page will show you how to make them.

Head with Headset/Eyes

This is very similar to the avatar already created in the tutorials but has added Unity primitives

Submarine

This is a little bit more complex, but the model still follows the headset and uses primitives

Building a New Avatar:

The most important thing to complete before trying to build an avatar is to decide what object you want your avatar to follow. For most people this is simply just the headset and the hand controllers, but you can also follow the player rig, or something else attached to the player. Once you have decided all of the things you want your avatar to follow, create an empty game object with the following structure of empty game objects inside of it:

Avatar -> parent object with Photon View component attached

Head -> sub object with Photon Transform View component attached

Left Hand -> sub object with Photon Transform View component attached

Right Hand -> sub object with Photon Transform View component attached

If you don't want hand models, just don't include them. From here all you have to do is include Unity primitives inside of these empty game objects. If you wanted to build the head on avatar in the left image the structure would look like this:

Head -> empty game object attached to the Avatar empty game object (see above)

Headset -> Cube primitive resized to be offset along the forward axis

Left Eye -> Sphere primitive resized and offset to be poking out of the headset

Left Pupil -> Sphere primitive resized and offset to be poking out of the left eye

Right Eye -> Sphere primitive resized and offset to be poking out of the headset

Right Pupil -> Sphere primitive resized and offset to be poking out of the right eye

The easy thing about building avatars in Unity is that you don't have to worry about the Photon View and Photon Transform View components after attaching them to the parent game objects. This is because when an object with one of those components is moved in the application it will also move all of it's children which makes the children automatically follow the parent objects. Pretty simple!

Possible Extensions:

There are two main ways to get better avatars in Unity instead of building your own using the built in Unity primitives. The first way is to download Blender and build your own model using the application. Blender has a very steep learning curve but has many powerful tools to allow you to build much more detailed objects than you can using the built in Unity primitives. From there you can export the model to Unity (preferably in parts so that you can do the empty game object strategy mentioned earlier to give objects the correct Photon views and positions) and then all you have to do is set up your avatar again using the Photon components and empty game objects.

The second way to get better avatars is to download them from the Unity Asset Store. The Asset store has hundreds of different avatars to choose from with the only constraint being price. There are free ones in the store but they are frequently anime characters to be used in the popular game, VR Chat on the Oculus store. Either way you can still use these character models in your own Unity projects as long as you make sure your Photon components are set up correctly.

Whether you build your own Avatar in Unity, Blender, or download one off of the Unity Asset store, there is a lot of support out there to help you get/create the avatar that is right for your application. Don't be afraid to ask for help on the Unity forums or Google. Most people want to help you succeed.