Join/create room after disconnecting goes wrong

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 objects 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

Answers

  • Kurtav
    Kurtav ✭✭
    edited May 2017
    Options
    IBuckly said:

    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 objects 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


    Need your code. I can not help without code
  • IBuckly
    IBuckly
    edited May 2017
    Options
    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");
         }
  • IBuckly
    Options
    Anyone??
  • Tinasious
    Options
    How are you calling the RPC ? I mean what are the sender options you set ?
  • IBuckly
    Options
    The RPC call is for All. Not AllBuffered if this is what you mean.
  • Tinasious
    Options
    I am not exactly sure how you are calling the rpc in your code but with the "All" option the RPC will be called immediately on the calling client and then sent to others. Are you by any chance calling Spawn locally on the client and then calling the RPC, in which case the code will be executed twice and would explain the 2 instances. In that case "Others" would be the PhotonTarget to use.
  • IBuckly
    IBuckly
    edited May 2017
    Options
    This is how I call the RPC for the Spawn ();

    Any idea how I can find if I call it locally?
    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);
        }
    
    //The Start button is only visible for the master client (the one that creates the room)
            if (PhotonNetwork.isMasterClient)
            {
                RoomStartMessage.text = "Press the 'Start game' button to load the game";
    
                StartGameObject.transform.GetComponent<Button>().onClick.AddListener(() =>
                {
                    PhotonNetwork.room.IsOpen = false;
                    photonView.RPC("LoadGame", PhotonTargets.Others);
                });
            }
    
    [PunRPC]
        public void LoadGame ()
        {
            SceneManager.sceneLoaded += (scene, loadscene) =>
            {
                if (SceneManager.GetActiveScene().name == "11-Online")
                {
                    Spawn();
                }
            };
            PhotonNetwork.LoadLevel("11-Online");
        }
  • IBuckly
    Options
    I still can't fix this problem. Someone? I really need help
  • IBuckly
    Options
    Just leave it. No one that helps... I just fixed it myself... Thanks to myself