Finally i fixed it, I'll post my solution here because I don't know if it's a PUN bug, but I had to make my Init.cs inherit from normal monobehaviour and not from photon.monobehaviour, also I needed to do another script inherit from photon.monobehaviour to manage other things, now when I push 'leave' button photon correctly removes all player prefabs and updates everything, I'm pretty happy. This enum defines the set of MonoMessages Photon Unity Networking is using as callbacks. Implemented by PunBehaviour. Much like 'Update' in Unity, PUN will call methods in specific situations. Often, these methods are triggered when network operations complete (example: when joining a room).
-->In this tutorial, you will prepare for creating a shared experience using Photon Unity Networking (PUN). You will learn how to create a PUN app, import PUN assets into your Unity project, and connect your Unity project to the PUN app.
Objectives
- Learn how to create a PUN app
- Learn how to find and import the PUN assets
- Learn how to connect your Unity project to the PUN app
Creating and preparing the Unity project
In this section, you will create a new Unity project and get it ready for MRTK development.
First, follow the Initializing your project and deploying your first application, excluding the Build your application to your device instructions, which includes the following steps:
- Creating the Unity project and give it a suitable name, for example, MRTK Tutorials
- Creating and configuring the scene and give the scene a suitable name, for example, MultiUserCapabilities
Then follow the Changing the Spatial Awareness Display Option instructions to:
- Change the MRTK configuration profile for to the DefaultHoloLens2ConfigurationProfile
- Change the spatial awareness mesh display options to Occlusion.
Enabling additional capabilities
In the Unity menu, select Edit > Project Settings... to open the Player Settings window, then locate the Player > Publishing Settings section:
In the Publishing Settings, scroll down to the Capabilities section and double-check that the InternetClient, Microphone, SpatialPerception, and GazeInput capabilities, which you enabled during the Configuring the Unity project step above, are enabled.
Then enable the following additional capabilities:
- InternetClientServer capability
- PrivateNetworkClientServer capability
Installing inbuilt Unity packages
In the Unity menu, select Window > Package Manager to open the Package Manager window, then select AR Foundation and click the Install button to install the package:
Note
You are installing the AR Foundation package because it is required by the Azure Spatial Anchors SDK you will import in the next section.
Importing the tutorial assets
Add AzurespatialAnchors SDK V2.7.1 into your unity project, to add the packages please follow this tutorial
Download and import the following Unity custom packages in the order they are listed:
After you have imported the tutorial assets your Project window should look similar to this:
Tip
For a reminder on how to import a Unity custom package, you can refer to the Importing the tutorial assets instructions.
Note
After importing the MultiUserCapabilities tutorial assets package, you will see several CS0246 errors in the Console window stating that the type or namespace is missing. This is expected and will be resolved in the next section when you import the PUN assets.
Importing the PUN assets
In the Unity menu, select Window > Asset Store to open the Asset Store window, search for and select PUN 2 - FREE from Exit Games, click the Download button to download the asset package to your Unity account.
When the download is complete, click the Import button to open the Import Unity Package window:
In the Import Unity Package window, click the All button to ensure all the assets are selected, then click the Import button to import the assets:
Once Unity has completed the import process, the Pun Wizard window will appear with the PUN Setup menu loaded, you can ignore or close this window for now:
Creating the PUN application
In this section, you will create a Photon account, if you don't already have one, and create a new PUN app.
Navigate to the Photon dashboard and sign in if you already have an account you want to use, otherwise, click the Create One link and follow the instructions to register a new account:
Photon Unity Network
Once signed in, click the Create a New App button:
Photon Unity Documentation
On the Create a New Application page, enter the following values:
- For Photon Type, select PUN
- For Name, enter a suitable name, for example, MRTK Tutorials
- For Description, optionally enter a suitable description
- For Url, leave the field empty
Then click the Create button to create the new app:
Once Photon has finished the creation process, the new PUN app will appear on your dashboard:
Connecting the Unity project to the PUN application
In this section, you will connect your Unity project to the PUN app you created in the previous section.
Photon Unity Server
On the Photon dashboard, click the App ID field to reveal the app ID, then copy it to your clipboard:
In the Unity menu, select Window > Photon Unity Networking > PUN Wizard to open the Pun Wizard window, click the Setup Project button to open the PUN Setup menu, and configure it as follows:
- In the AppId or Email field, paste the PUN app ID you copied in the previous step
Then click the Setup Project button to apply the app ID:
Once Unity has finished the PUN setup process, the PUN Setup menu will display the message Done! and automatically select the PhotonServerSettings asset in the Project window, so its properties are displayed in the Inspector window:
Photon Unity Networking 2

Congratulations
You have successfully created a PUN app and connected it to your Unity project. Your next step is to allow connections with other users so that multiple users can see each other.
For this Unity Multiplayer Game Tutorial on how to make a multiplayer game in Unity using the Photon 2 plugin, we will be showing you how to create a Photon room controller script which will control some of the interactions between players connected to the same room. It will also control the start of the game and how the players are loaded into the multiplayer scene. There are two different ways to start a multiplayer game. One is a continuous load and the other is a delayed start. a continuous load means players can join and leave a game in progress at any time. whereas a delayed start is when all the players have to be connected to the room before the game can start. Our code in this video will handle both these methods and you will be able to switch between the two by changing a single bool.
We will start this lesson by creating two new C# scripts the first will be called Multiplayer Setting and the next one will be called Photon Room. We will then open these C# scripts up.
We will start in the Multiplayer Settings. We will first need to create some new variables. We can then delete the start and update functions. we will then create an awake function and set up a singleton for this C# script. We will then save this script after which we will make a few changes to our room creation in the lobby script.
We then need to open our Photon Room script. Inside this script, we will create some more variables. We will then create some code that will either load the player right into the multiplayer scene as soon as they connect to the room or the game will have a delayed start where all the players will load into the multiplayer scene at the same time. Once we have finished creating this script we will then save and return to Unity.
Photon Unity Asset Store
In Unity, we need to create an empty game object and attach our Photon room script. We will also create an empty game object and attach our multiplayer settings script. We then need to set the variable of these scripts. We will then create a placeholder for our Photon player object.
If you have followed along with the video tutorial you should then be able to build your project and run your multiplayer game, connect at least two instances of your game. This should then load your players into the multiplayer scene and you should be able to see the two players.
