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.