Destroy player from network after rejoining room

Options
When I create or join a room, everything seems to be okay. But when I disconnect from photon and create or join another room, I have 2 players with mine photonview. The previous player with mine photonview does still exist. Anyone that could help me? It drives me crazy, I even don't know how to explain because of this headache. Please help me out

My code is quite simple.

In the NetworkManager, I use this part of script

// This buttonEvent is only for the masterclient
[PunRPC]
public void LoadGame ()
{
SceneManager.sceneLoaded += (scene, loadscene) =>
{
if (SceneManager.GetActiveScene().name == "GameRoom")
{
Spawn();
}
};
PhotonNetwork.LoadLevel("GameRoom");
}

void Spawn()
{
GameObject g = PhotonNetwork.Instantiate("Player", new Vector3(Random.Range(-2.7F, 1.1F), 0, Random.Range(-22F, -16.5F)), Quaternion.Euler(0, 90, 0), 0);
}


And ingame, I use this part

public void ReturnToMenu()
{
PhotonNetwork.autoCleanUpPlayerObjects = true;
PhotonNetwork.Disconnect();
Application.LoadLevel("MainMenu");
}

Answers

  • [Deleted User]
    Options
    Hi @IBuckly,

    when creating the room do you set PlayerTtl or EmptyRoomTtl to another value than zero? This would allow a client to rejoin in a certain amount of time and means that the server keeps the client's instantiated objects in its memory. Can you also confirm that you really join another room when connecting to Photon again? How long do you wait before connecting again? I guess you are doing this mostly instantly, don't you?
  • IBuckly
    Options
    > @Christian_Simon said:
    > Hi @IBuckly,
    >
    > when creating the room do you set PlayerTtl or EmptyRoomTtl to another value than zero? This would allow a client to rejoin in a certain amount of time and means that the server keeps the client's instantiated objects in its memory. Can you also confirm that you really join another room when connecting to Photon again? How long do you wait before connecting again? I guess you are doing this mostly instantly, don't you?

    Thanks for your reaction. But I already fixed it. It took many days for me to solve the problem and finaly found it. It needed to set the value of the player to zero when leaving. One sense of code that could make me crazy. But thanks for your reply. I will ask you a lot of questions in the future
  • Shibli
    Options
    @IBuckly what do you mean you had to set the player to zero? I'm having the same problem.