This document is about: PUN 1
SWITCH TO

PUN Classic (v1.x) and Bolt are outdated and will not receive further updates. Of course, existing PUN Classic and Bolt projects will continue to run. New projects should use Fusion or Quantum.

5 - Building the Player

This section will guide you to create from scratch the player Prefab that will be used in this tutorial so that we cover every step of the creation process.

It's always a good approach to try and create a player Prefab that can work without PUN being connected so that it's easy to quickly test, debug and make sure everything at least works without any network features.
Then, you can build up and modify slowly and surely each feature into a network compliant character:
Typically, user input should only be activated on the instance owned by the player, not on other players' computers.
We'll cover this in details below.

The Prefab Basics

The first and important convention to know about PUN is that for a Prefab to be instantiated over the network, it needs to be inside a Resources folder, it can not be otherwise.

The second important side effect of having Prefabs inside Resources is that you need to watch for their names.
You should not have two Prefab under your Assets' Resources paths named the same, as Unity will pick the first one it finds, so always make sure that within your Project Assets, there is no two Prefabs within a Resources folder path that is named the same. We'll get to that soon.

We are going to use the Kyle Robot that Unity provides as a free asset.
It comes as an Fbx file, which is generated by 3D software like 3ds Max, Maya, cinema4d and the likes.
This is out of scope for this tutorial to cover the creation of the mesh and animation on these tools, however essential for creating your own characters and animations.
This "Robot Kyle.fbx" is located in "Assets\Photon Unity Networking\Demos\Shared Assets"

Kyle Robot Fbx Asset
Kyle Robot Fbx Asset
Here is one way to start using the `Kyle Robot.fbx` for your player:
  1. In your "Project Browser", create a folder named exactly "Resources" somewhere, typically it's suggested that you organized your content, so could have something like "PunBasics_tutorial\Resources"
  2. Create a new empty scene and save it as Kyle Test in "PunBasics_tutorial\Scenes".
    The purpose of the "Kyle Test" scene is solely to create the prefab and set it up.
    You can get rid of the scene once this is done.
  3. Drag and drop Robot Kyle onto the "Scene Hierarchy".
  4. Rename the GameObject you've just created in the hierarchy to My Robot Kyle
  5. Drag and drop My Robot Kyle into "PunBasics_tutorial\Resources"

We have now created a Prefab that is based on Kyle Robot Fbx asset and we have an instance of it in the hierarchy of your scene Kyle Test.
Now we can start working on it.

CharacterController

  1. Let's add a CharacterController Component to My Kyle Robot instance in the hierarchy.
    You could do this directly on the Prefab itself but we need to tweak it, so this is quicker this way.

This Component is a very convenient Standard Asset provided by Unity for us to produce faster typical characters using Animator, so let's make use of these great Unity features.

Back to top