Reloading scene issue
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Reloading scene issue
LeonidB
2017-08-11 07:00:55
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:
- to prevent unwanted objects spawn after reconnect use PhotonNetwork.DestroyAll() on Master client on scene change
- 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! :)
roycefernandes3
2020-05-02 17:17:21
Hey there,
Was having the same problem of restarting a scene. Is the above method still good or have u found a better method.
hellohallo
2020-06-22 03:34:13
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.
yaoling1997
2022-03-24 10:53:34
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.
aysegullarpacii
2022-08-24 10:42:06
I still can't reload the same scene. The solution to switch to an empty scene first didn't work either...
aysegullarpacii
2022-08-24 10:48:57
@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.
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.
Back to top