Posted on

Unity Multiplayer Tutorial – Setup

Photon 2 Tutorial

Welcome to this new tutorial series on creating multiplayer video games in Unity using the Photon 2 PUN plugin. For this lesson, we will show you how to download, install and set up the Photon 2 plugin in your Unity projects. Before you follow along with any of the other lessons in this tutorial series, you must complete this video. We will be providing the downloadable add-ons for all the other videos in this series but these add-ons will not include the original Photon plugin. You must get that from the official Photon website.

Photon Website: https://www.photonengine.com/
PUN 2 Plugin:
https://assetstore.unity.com/packages/tools/network/pun-2-free-119922
Payment Plans: https://www.photonengine.com/en/pun/pricing
Documentation: https://doc.photonengine.com/en-us/pun/current/getting-started/pun-intro
Scripting API: https://doc-api.photonengine.com/en/pun/v2/index.html

Creating a Photon Account

The first thing you will need to do in this lesson is to create a Photon account. Once you have registered an account you will need to create a new Photon app project. You will then need to fill out some information about your multiplayer game and then you will click create. After creating a new app you will need to copy the AppID for later.

Setting up a Network Connection

Back in Unity, you will need to go to the Unity Asset Store and search for the PUN 2 free plugin. You will need to download and install this plugin in your project. After importing this plugin a new window will appear. This is the PUN wizard and you need to paste your project AppID into this window and then you will click setup project. The next thing we will do is establish our very first connection to the Photon master server. To do this we will need to create a new script. In this new script, the only thing we will do for this tutorial is to initialize the network connection.

Posted on

Fixing Duplicate View ID with Photon 2 in Unity

For this Unity Multiplayer Tutorial, we will be looking at fixing the error that occurs when we load back to the main menu scene. When we disconnect for the multiplayer game and return to the main menu scene we receive an error that says PhotonView ID duplicate found. If you need more help with the Photon plugin and making multiplayer games in Unity then join our discord and ask your questions there.

This is an error that you might be receiving in Unity 3D while using the Photon 2 plugin. The error we will be talking about in this lesson happens when you have a Photon View object that is set to DontDestroyOnLoad and then you load back into the first scene of that object. As the error message states, Photon will fix this problem for you making this not as big a deal as other error messages. We will teach you how to debug this error and show you how to fix your project so you don’t receive this error message again.

The Object that is producing this error is our PhotonRoomController. Because this object is not being destroyed when we load from scene to scene we end up having more than one of these objects when we load back into the main menu scene and because the Room controller has a Photon view we have two photon views with the same ID number. The best way to fix this is to just destroy the current Room controller when we disconnect from the Multiplayer match and before we load back into the main menu scene.

Posted on

Fixing Photon View &v with Photon 2 in Unity

For those of you who are trying to use the Photon 2 Plugin with the latest version of Unity 2018, you may be receiving a weird bug where the Photon View script cannot be added to the inspector through the Add Component button. This lesson will help you understand how to fix this problem so that you can keep working without missing a beat.