Auto connection after leaving a room?

Options
Hey there. When I leave the current room by calling
PhotonNetwork.LeaveRoom();
the PUN automatically connects to another (or the same) room without even asking if i want to!

Here is log


So it seems like this is default behaviour for PUN, and all the wrong magic happens at
NetworkingPeer:OnStatusChanged(StatusCode) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1922)

How do I fix this?
I want to leave the room and stay connected to the server, and join another room only when I press some button, or something like this

Comments

  • Gage_IAG
    Options
    Make sure your not calling the wrong scene from the LoadScene() function from your code somewhere or on the OnLeftRoom() callback.

    Heres a sample that is provided by Photon that shows how to leave a room while still connected to the Photon servers.
    // Callback from Photon when you leave a room
        public void OnLeftRoom() {
            Debug.Log("PhotonNetwork : Client has left the room");
            SceneManager.LoadScene("01.Launcher");
        }
    
        // Called from a button or somewhere external
        public void LeaveRoom() {
            Debug.Log("Manual Room Exit: Leaving room - " + PhotonNetwork.room.Name);
            PhotonNetwork.LeaveRoom();
        }
    Obviously you need to include deriving from Photon.PunBehaviour and add using UnityEngine.SceneManagement; to the script.

    Does this help?
  • ChazAshley
    edited February 2017
    Options
    As I can see I don't call anything after leaving the room.
    Here is full code of a class which I use in my scene

    using System.Collections; using System.Linq; using UnityEngine; using UnityEngine.UI; namespace Com.Hikkainc.MazeBattle { public class Launcher : Photon.PunBehaviour { public Button StartGameButton, LeaveGameButton; public Text CountDownText; public PlayerPlaceholder[] PlayerPlaceholders; public GameObject PlaceholdersPanel; public GameObject WaitingWheel; public Transform WaitingArrow; public string GameSettings = "1"; public int MaxPlayers = 4, MinCountOfPlayers = 2, LevelToLoad = 1; void Start() { CountDownText.gameObject.SetActive(false); PlaceholdersPanel.SetActive(false); WaitingWheel.SetActive(false); LeaveGameButton.gameObject.SetActive(false); PhotonNetwork.autoJoinLobby = false; PhotonNetwork.automaticallySyncScene = true; } public void FindRoom() { StartGameButton.gameObject.SetActive(false); LeaveGameButton.gameObject.SetActive(true); Debug.Log("<color=green>Message:</color> Finding room..."); if (PhotonNetwork.connected) { OnConnectedToMaster(); } else { Debug.Log("<color=green>Message:</color> Trying to connect..."); PhotonNetwork.ConnectUsingSettings(GameSettings); } } public void LeaveRoom() { PhotonNetwork.LeaveRoom(); PlaceholdersPanel.SetActive(false); WaitingWheel.SetActive(false); LeaveGameButton.gameObject.SetActive(false); StartGameButton.gameObject.SetActive(true); RemoveFromPlaceholders(true); } public void StartGame() { PhotonNetwork.room.IsOpen = false; StartCoroutine("StartCountDown"); } public IEnumerator StartCountDown() { int i = 10; while (i > 0) { CountDownText.text = i.ToString(); yield return new WaitForSeconds(1); } if (PhotonNetwork.countOfPlayers >= MinCountOfPlayers) { Debug.Log("<color=green>Message:</color> Starting the game!"); PhotonNetwork.LoadLevel(LevelToLoad); } else { Debug.Log("<color=red>Message:</color> Count of players is less than min count of players required"); CountDownText.text = string.Empty; } } [PunRPC] void SetPlayerReady(int playerId) { } public override void OnConnectedToMaster() { Debug.Log("<color=green>Message:</color> Joining room..."); PhotonNetwork.JoinRandomRoom(); WaitingWheel.SetActive(true); PlaceholdersPanel.SetActive(true); } public override void OnPhotonRandomJoinFailed(object[] codeAndMsg) { Debug.Log("<color=red>Message:</color> Failed to join a random room."); Debug.Log("<color=green>Message:</color> Creating a room..."); PhotonNetwork.CreateRoom(null, new RoomOptions() {MaxPlayers = (byte) MaxPlayers}, null); } public override void OnPhotonPlayerConnected(PhotonPlayer player) { Debug.Log("<color=yellow>Message:</color> A user has joined to the room."); if (PhotonNetwork.countOfPlayers == MinCountOfPlayers) { StartGameButton.interactable = true; } AddToPlaceholders(); } public override void OnPhotonPlayerDisconnected(PhotonPlayer player) { Debug.Log("<color=yellow>Message:</color> A user has left the room."); if (PhotonNetwork.countOfPlayers < MinCountOfPlayers) { StartGameButton.interactable = false; } RemoveFromPlaceholders(); } public override void OnJoinedRoom() { Debug.Log("<color=green>Message:</color> Joined to a room!"); AddToPlaceholders(); } private void AddToPlaceholders() { PlayerPlaceholders.First((pp) => { return !pp.IsActive; }).SetActive(true); } private void RemoveFromPlaceholders(bool all=false) { if (all) { foreach (var pp in PlayerPlaceholders) { pp.SetActive(false); } return; } PlayerPlaceholders.Last((pp) => { return pp.IsActive; }).SetActive(false); } } }
  • okay okay, it's my fault, now it's all right
  • AqibSadiq
    AqibSadiq
    edited November 2018
    Options
    How did you solve it.
    I am Getting the Same Problem.