Disconnecting after leave

Options
I have a game and during a loading screen i try to leave and then join a room. The fist time i join a room without being in one first it runs fine. but then i try to leave then join/create one but it seems after leaving and trying to join it has an error and disconnects me.

ERROR:
Cannot send op: 226 Not connected. PeerState: Disconnecting
UnityEngine.Debug:LogError(Object)
PhotonHandler:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:168)
NetworkingPeer:DebugReturn(DebugLevel, String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:796)
ExitGames.Client.Photon.EnetPeer:EnqueueOperation(Dictionary`2, Byte, Boolean, Byte, Boolean, EgMessageType)
ExitGames.Client.Photon.PeerBase:EnqueueOperation(Dictionary`2, Byte, Boolean, Byte, Boolean)
ExitGames.Client.Photon.PhotonPeer:OpCustom(Byte, Dictionary`2, Boolean, Byte)
ExitGames.Client.Photon.PhotonPeer:OpCustom(Byte, Dictionary`2, Boolean)
LoadbalancingPeer:OpJoinRoom(String, Hashtable) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/LoadbalancingPeer.cs:132)
NetworkingPeer:OpJoin(String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:710)
PhotonNetwork:JoinRoom(String) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonNetwork.cs:1202)
LoadScreen:Update() (at Assets/Servers/Scripts/LoadScreen.cs:32)


CODE:
[code2=csharp]using UnityEngine;
using System.Collections;

public class LoadScreen : MonoBehaviour
{
private int m_LoadState = 0;
AsyncOperation m_LevelLoader = null;
public string m_LoadLevelName = "";

// Use this for initialization
void Start ()
{
GameObject networkObject = GameObject.FindGameObjectWithTag("network");
m_LoadLevelName = networkObject.GetComponent<LevelManager>().levelName;
}

// Update is called once per frame
void Update ()
{
switch(m_LoadState){
case 0:{
if(PhotonNetwork.room == null){
m_LoadState = 1;
}
else{
PhotonNetwork.LeaveRoom();
m_LoadState = 5;
}
break;
}
case 1:{
PhotonNetwork.JoinRoom(m_LoadLevelName);
m_LoadState = 6;
break;
}
case 2:{
if(m_LevelLoader == null)
{
m_LevelLoader = Application.LoadLevelAsync(m_LoadLevelName);
}
break;
}
}
}

void OnGUI()
{
if(m_LevelLoader != null)
{
GUI.Label(new Rect(10, 400, 300, 20), "Loading: " + (m_LevelLoader.progress*100) + "%");
}
}

void OnPhotonJoinRoomFailed(){
Debug.Log("Make Room");
PhotonNetwork.CreateRoom(m_LoadLevelName);
}

void OnJoinedRoom(){
m_LoadState = 2;
}

void OnLeftRoom(){
m_LoadState = 1;
}
}[/code2]

Comments

  • Tobias
    Options
    Hm. You ran into a problem I didn't properly describe, I guess.
    For our loadbalancing to work properly and effectively, you can only create/join rooms while you are connected to the Master Server. You don't have to join a lobby but you can't create another room while being in one.

    Leave the room and wait until OnConnectedToMaster (or OnJoinedLobby) is called. Then join/create another room.
  • Thanks so much OnJoinedLobby was what fixed it! You wont beleive how long I was trying to make it work. Using Lite peer server was much easier to get this working in that but that was custom so thanks for helping out with doing something like it in LoadBalancing

    P.S. is there a way to send an rpc to another room? I have a chat and now that i got the rooms to work only sends in the room which is fine and i knew would happen but i wanted to know if there was a way to send messages(done with rpc atm) to other rooms so im able to do system messages and wispering
  • Tobias
    Options
    I'm glad my reply helped you. I'm sorry you ran into the issue in the first place.

    About RPCs to other rooms: This is not possible. Rooms are fully distinct and separated.
    We are working on a Chat API which will work across rooms and if you wanted to, even across games. It's not yet released but we are about to test it and it should become available this year.
  • Ok thank you very much ill try to think of a way to handle it for now then.