PUN2 scene not syncing

Hi all.
I want to start new scene when both players clicked ready.
For this I am using RPC
This is my code:

[PunRPC]
void SetNext(int id)
{
if (id == 1)
p1Restart = true;
else
p2Restart = true;

CheckNext();
}

void CheckNext()
{
if (p1Restart && p2Restart && PhotonNetwork.IsMasterClient)
{
PhotonNetwork.LoadLevel(1);
}
}


Sometimes it is working good, but sometimes MasterClient loads new level and other player stays at previous.
I can't find out when it's happening, it's just random.
I am using PUN2 and can't say was this an issue in PUN1 or not, because I didn't have this check when I was using PUN1.
Please help.

Comments

  • I'm having the same issue. setting PhotonNetwork.AutomaticallySyncScene = true seems to do nothing. I have to program it so each user loads their own scene.
  • Hi @luvjungle, hi @KevTheUnityDev,

    PhotonNetwork.AutomaticallySyncScene has to be enabled on each client individually, this isn't a synchronized property or similar. When enabled, the MasterClient (and only him) can use PhotonNetwork.LoadLevel(...);, which will 'force' each client to load that scene.
  • luvjungle
    luvjungle
    edited October 2018
    It is enabled, sorry not to mention it.
    As I wrote in original post, sometimes it is working good, but sometimes it fails. No errors in console with full debug and additional debug info unfortunately.
  • You can add some Debug.Log calls to the LoadLevelIfSynced function. You can find it in the PhotonNetworkPart class. It gets called, when the Custom Room Properties are updated (the synchronized scene is stored in them). Maybe you can figure out, what's wrong in your case. I have run some tests and never noticed such a behaviour. If you can't solve this, it would be great, if you can share a repro case, so that I can take a closer look at the problem.
  • I was having this same issue. After looking at the provided function it appears that the function skips the LoadLevelIfSynced call if the scene being loaded is the same as the lobby's properties. So you can't load the same scene that the lobby was initialized in. LoadLevelIfSynced just ends up calling PhotonNetwork.LoadLevel(...); for each player anyways, so just don't test for IsMasterClient and tell everyone to load the new scene