This document is about: PUN 2
SWITCH TO

PUN 2 is in maintenance / LTS mode. Aside from some fixes no further feature updates are planned. Of course, existing PUN 2 projects will continue to run. New projects should consider Fusion or Quantum.

5 - Building the Player

This section will guide you to create the player Prefab that will be used in this tutorial from scratch, so we'll 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 detail below.

The Prefab Basics

The first and important rule to know about PUN is, that a Prefab, that should get instantiated over the network, has to be inside a Resources folder.

The second important side effect of having Prefabs inside Resources folders 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 with the same name. 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 created with a 3d software like 3ds Max, Maya, cinema 4D and the likes.
Covering the creation of the mesh and the animation with those software, is out of scope for this tutorial.
This Robot Kyle.fbx is located in "\Assets\Photon\PhotonUnityNetworking\Demos\Shared Assets\Models".

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 of Kyle Robot Fbx asset, and we have an instance of it in the hierarchy of your scene Kyle Test.
Now we can start working with 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