Issue when master client leave

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

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).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Issue when master client leave

Clevereen
2020-11-25 20:43:41

Hello all,

I'm developping a game with 2 players using a same room. So one is master client and the other a client.
i have a big issue when the master client leaves the room :

1-If the master client leaves the room, it seems that the scene is "reset" to initial loading state. For an example I intentionally destroy a game object (with no photonview), when master client leave that object appears again and all instantiated game object are destroyed.
2- but if the client leaves the room, all the instantiated game object remains.

I want only the master client instantiated game object to be destroyed and keep the scene exactly the same way.

Comments

Clevereen
2020-11-25 21:46:41

Okay! I found what was causing this problem!
If you want to remain in the scene with all the object :
DON'T USE

void start(){

//the player will load the scene only if the master client loads the scene  
PhotonNetwork.AutomaticallySyncScene = true;  
}

private void loadScene()  
{

if (!PhotonNetwork.IsMasterClient) //if we are not the master client  
                        return;  
PhotonNetwork.LoadLevel(sceneLvl)  
}  

but use this instead:

void Start()  
{  
PhotonNetwork.AutomaticallySyncScene = false;  
}

private void loadScene(){

PhotonNetwork.LoadLevel(){  
SceneManager.LoadScene(sceneLvl);  
}
Back to top