Reloading scene issue

Hi guys! I'm new to Photon Networking. Recently faced strange problem with scene syncing.
In my project after the end of the match the scene must be reloaded.
So, all the client on the same scene.
What i do:
PhotonNetwork.automaticallySyncScene = true;
if (PhotonNetwork.isMasterClient)
{
            PhotonNetwork.LoadLevel(SceneManager.GetActiveScene().name); //restart the game
}
The scene is restarting only on master client.
If i change scene to another, it works ok.
Tell me please, is there something i do wrong? Is there some workaround except RPCs?
Thank you!

Comments

  • One more problem appeared. If i try to restart the scene on clients by RPC (like this)
        public void RestartGame()
        {
            if (PhotonNetwork.isMasterClient)
            {
                StartCoroutine(ReloaSceneCor());  
            }
        }
    
        IEnumerator ReloaSceneCor()
        {
            //send RPC to other clients to load my scene
            photonView.RPC("LoadMyScene", PhotonTargets.Others, SceneManager.GetActiveScene().name);
            yield return null;
            PhotonNetwork.isMessageQueueRunning = false;
            PhotonNetwork.LoadLevel(SceneManager.GetActiveScene().name); //restart the game
        }
    
        [PunRPC]
        public void LoadMyScene(string sceneName)
        {
            Debug.Log("REcieved RPC " + sceneName);
            PhotonNetwork.LoadLevel(sceneName); //restart the game
        }
    it works, BUT if i restart the scene multiple times and the client disconnects and connects again, hi see the "ghosts" - player prefabs of master client, spawned each time scene was restarted.
    That is strange.
  • Hi guys! If anyone is facing the same issue:
    1) to prevent unwanted objects spawn after reconnect use PhotonNetwork.DestroyAll() on Master client on scene change
    2) you can restart scene by RPC or by using empty scene. So first you move to empty scene (PhotonNetwork.LoadLevel("myEmptyScene") and then you reload your previously loaded scene.

    Cheers! :)
  • Hey there,
    Was having the same problem of restarting a scene. Is the above method still good or have u found a better method.
  • I'm having exactly the same issue. Transitioning through an empty scene causes a pretty long delay. Is there any better solution?
  • same!!! Would love an update about this.

  • It's 2022 years now, the problem is still there😏

  • Yes, scene reload never got implemented. You should be able to load a tiny scene then re-load the one you want reloaded. As a workaround.

    Adding additive scenes, reloading and maybe Addressables wasn't considered for PUN 2, which is a dated approach. We support this and much more in Fusion, which is a better choice for current projects.

  • I still can't reload the same scene. The solution to switch to an empty scene first didn't work either...

  • @LeonidB Can you write sample code so I can find where I'm doing wrong?

  • This might be a dead thread but I am having a similar problem. I reloaded the game by loading into a small scene and reloading the same scene. While it does work when I reload the game the first time, when I try to reload it a second time, only the MasterClient gets loaded in but not the others. I just found it curious why it works when I reload it the first time but not a second. Hopefully, someone has some input or came across this problem as well.

  • Tobias
    Tobias admin
    edited October 2022

    PUN does not really support reloading. Maybe you load the scene initially, without having to do this via network? Then, when you "reload the first time" it is actually doing the network syncing for the first time?

    You could possibly load another scene in-between or look up how to time scene loading and using the "message queue". One more option might be to modify PUN. Use an RPC to clear everyone's loaded scene value, then the Master Client could once more set the current scene as the one to load.