When Master leaves, all leave

Options
Since upgrading to unity 5.3.4 and PUN ver 1.66 (in release *** Version 4.0.5.1 (18. January 2016 - rev3187))
and changing to US server.

Players Connecting to room ok, controlling players ok.

Other players can come and go, but if master leaves, all other players get bumped out.

Thought it may be my code (maybe still is), but not sure where to look, have removed scene owned objects spawned by master.

was using OnDisconnectedFromPhoton() to do stuff, but have removed these too.

It was working a few months ago, thought I had the photon multi nailed down and was working on my cash register part.

Any ideas on where to look or to find exactly what is happening?
thanks

Comments

  • kingsley
    Options
    This is driving me mad, a week gone chasing my tail, is there any settings that could produce this?
  • Lorcan
    Options
    Do you mind posting the code?
  • kingsley
    kingsley ✭✭
    edited April 2016
    Options
    don't mind, but don't know where to start as having difficulty in narrowing down what is going on.
    I use something similar to the "worker menu" demo in the lobby, but also access a database via PHP to access some variables.
    Then join a room, if join fails, create one.

    After joining the room, if are the master then setup a whole heap of other variables, write some to a database. Make variables available for others as they join the room. eg
    windSpeedMin = (float)PhotonNetwork.room.customProperties["wSpeed"];
    Later in time if there are more than 1 in the room then the master sends rpc's to create or reset variables, clocks etc. eg
    pvScripts.RPC("windCreationMC", PhotonTargets.AllViaServer, "osc", ...

    All the functions of the game seem to work, up until the master leaves by calling
    SceneManager.LoadScene(SceneToLoad); // "Menu"

    When the master arrives at the new scene it runs:
    if (PhotonNetwork.connected)
            {
                PhotonNetwork.Disconnect();
            }
    Note there are no errors generated that I can see, not even sure where to put Debug.Log("message"); to see what is going wrong.

    If any "normal" player leaves, no problem,
    only when the master leaves it seems to force everyone to leave ... bumps them back to the "Menu".

    In game room I use demo code for instantiation, lots of other code for game play:

    Worker In Game code:
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    using UnityEngine;
    using UnityEngine.SceneManagement;
    
    public class WorkerInGameMC : Photon.MonoBehaviour
    {
    	public Transform playerPrefab;
    	private GameObject boatClone ;
    	
    	public void Awake()
    	{
    //		Debug.Log ("workerInGameMC awake"  );
    		// in case we started this demo with the wrong scene being active, simply load the menu scene
    
    		if (!PhotonNetwork.connected)
    		{
                SceneManager.LoadScene(WorkerMenuSessionMC.SceneNameMenu);
                return;
    		}
    		
    		// we're in a room. spawn a character for the local player. it gets synced by using PhotonNetwork.Instantiate
    		//rack the boats up
    		int rackY = 10;
    		rackY = rackY + (PhotonNetwork.player.ID -1)*2;
    		boatClone = PhotonNetwork.Instantiate(this.playerPrefab.name, new Vector3(rackY, 0, -5), Quaternion.Euler(0 ,290 ,0), 0)  as GameObject;
    		PlayerValuesMC playerValuesMCScript = boatClone.GetComponent<PlayerValuesMC>();
    		playerValuesMCScript.instPlayerName = PhotonNetwork.playerName;
    		PhotonNetwork.player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable() { { "playerName", PhotonNetwork.playerName }}); //PlayerValuesMC.instPlayerName
    
    	}
    	
    	
    	public void OnMasterClientSwitched(PhotonPlayer player)
    	{
    		Debug.Log("OnMasterClientSwitched: " + player);
    		
    		string message;
    		InRoomChat chatComponent = GetComponent<InRoomChat>();  // if we find a InRoomChat component, we print out a short message
    		
    		if (chatComponent != null)
    		{
    			// to check if this client is the new master...
    			if (player.isLocal)
    			{
    				message = "You are Master Client now.";
    			}
    			else
    			{
    				message = player.name + " is Master Client now.";
    			}
    			
    			
    			chatComponent.AddLine(message); // the Chat method is a RPC. as we don't want to send an RPC and neither create a PhotonMessageInfo, lets call AddLine()
    		}
    	}
    	
    	public void OnLeftRoom()
    	{
    		Debug.Log("OnLeftRoom (local)");
          
            // back to main menu        
            SceneManager.LoadScene(WorkerMenuSessionMC.SceneNameMenu);
    	}
    	
    	public void OnDisconnectedFromPhoton()
    	{
    		Debug.Log("OnDisconnectedFromPhoton");
    
    	}
    	
    	public void OnPhotonInstantiate(PhotonMessageInfo info)
    	{
    		Debug.Log("OnPhotonInstantiate " + info.sender);    // you could use this info to store this or react
    	}
    	
    	public void OnPhotonPlayerConnected(PhotonPlayer player)
    	{
    		Debug.Log("OnPhotonPlayerConnected: " + player);
    	}
    	
    	public void OnPhotonPlayerDisconnected(PhotonPlayer player)
    	{
    		Debug.Log("OnPlayerDisconneced: " + player);
    	}
    	
    	public void OnFailedToConnectToPhoton()
    	{
    		Debug.Log("OnFailedToConnectToPhoton");
    		
    		// back to main menu        
    		SceneManager.LoadScene(WorkerMenuSessionMC.SceneNameMenu);
    	}
    }
    ++++++++++++++++++++++++++++++++++++++++++++++++++++


    But I don't get any debug messages either as master or other, no "left room" or "disconnect" or "OnMasterClientSwitched"

    It almost smells like I am missing a setting that allows a room to continue after the master leaves.

    Any suggestions?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @kingsley, I edited your post to add proper code format. Please use it next time.
  • vadim
    Options
    Hi @kingsley
    Did you try it without OnMasterClientSwitched implemented?
    What is in bumped out clients logs?
    Your master disconnection scenario is pretty complex. How disconnection is triggered? Is it possible that each time new master assigned, it disconnects immediately?
  • kingsley
    Options
    Thankyou JohnTube, I was looking for how to do that, but couldn't see how (it was late).

    Thanks Vadim,
    "Did you try it without OnMasterClientSwitched implemented?"
    Do you mean just commenting out
    OnMasterClientSwitched ?
    I don't get any "disconnection" debug log messages for either. any other logs to look in?
    "Is it possible that each time new master assigned, it disconnects immediately?"
    ... looks exactly like this, is there something in my room setup / connection settings ? that could trigger this?
  • kingsley
    Options
    Found it, sort of ...
    if PhotonNetwork.automaticallySyncScene = false; things seem to behave normally. ya! I get master leave and disconnect messages.
    But in your worker demo, it is set to "true" and the master switches correctly so there is something deeper down that is different.
    Meantime, It has forced me to clean up my createRoom / JoinRoom code as this was all written for previous version of Photon, when a failure of one did not automatically kick off the other. So I was joining rooms more than once.

    Question: by setting automaticallySyncScene = false what are the other ramifications of this?
    what is the line in the demo trying to tell me?:
    "// this makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically"
    thanks for the earlier returns, means a lot to know that I am not by myself.
  • vadim
    Options
    Non-master clients will not follow master client level loading if automaticallySyncScene = false. Please read PhotonNetwork.automaticallySyncScene help for details.
    The line just repeats what PhotonNetwork.automaticallySyncScene doc tells: load master level automatically on non-master clients when master calls PhotonNetwork.LoadLevel().
  • kingsley
    Options
    Thanks Vadim,
    So automaticallySyncScene = false, works for me, thanks for your help.

    Confirming that this line only effects non masters moving from 1 scene to another?
    I originally thought it may have deeper meaning like syncing variables (in the scene) or something.

    PS:
    going into the scene I use: PhotonNetwork.LoadLevel(SceneNameGame);

    Leaving the scene (and then the photon network connection) I use: SceneManager.LoadScene(SceneToLoad);

    So it looks like non-masters follow, no matter how the Master leaves if automaticallySyncScene = true;
    Is it possible that this is a bug, or the description needs to say:

    "PhotonNetwork.automaticallySyncScene = true; forces non-master clients to follow the Master to any new scene, 'load master level automatically on non-master clients' "

    I was sure my non masters were NOT following my Master up until latest updates in Unity and Photon, I have not worked in this part of my code for months.

    PPS, thanks for the product (and support), really looking forward to my game getting out of test and into live environment.
  • vadim
    vadim mod
    edited April 2016
    Options
    automaticallySyncScene does exactly what specified in its documentation.
    Of course the behavior described in assumption that master stays in a room at least until other clients received notification about level change. If you intentionally leave room somewhere in the middle, the behavior may depend on the moment when you have left.
    Leaving the scene (and then the photon network connection) I use: SceneManager.LoadScene(SceneToLoad);
    This does not look like conventional Photon workflow.