Multiple scene load on either LeaveRoom() or Disconnect()

Options
Hi,

My current setup includes a Scene0 (Main menu Screen) and Scene1(Multiplayer Map). When I try to leave the game using either LeaveRoom() or Disconnect() and do a sceneload scene0, the RoomManager(singleton DDOL netwrk script) makes the transition perfectly, but im sent back to the scene1 without any controls in around a second. happens on other clients. Master works fine.

My speculations,
1. Since AutoSyncScene is true, which makes the client pull back to the scene1 because master is in the scene1, but it was not the case.

Im attaching my Pause Game script and the singleton network class for reference.



PauseGame Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
using UnityEngine.SceneManagement;
using TMPro;
using Photon.Realtime;

public class PauseMenu : MonoBehaviourPunCallbacks
{
public GameObject escapeMenu;
public GameObject loadingTransition;
public TMP_Text leaveText;

public float fillSpeed;

public Image leaveGame;
public Image quitGame;

public Animator escapeMenuAnimator;

private bool isMenuOpen = false;
private bool gameState = false;

PhotonView PV;

protected ItemManager dropItem;
private GameObject dropWeapon;

// Start is called before the first frame update
void Start()
{

}

private void Awake()
{
PV = this.GetComponent<PhotonView>();
Debug.Log("Pause Menu Debug " + PV.Owner.NickName);

if (PV.IsMine)
{
escapeMenu = this.transform.Find("Canvas/EscapeMenu").gameObject;
loadingTransition = this.transform.Find("Canvas/LoadingScreen").gameObject;
escapeMenu.SetActive(false);
}
}

// Update is called once per frame
void Update()
{
if (PV.IsMine)
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (!isMenuOpen)
{
escapeMenu.SetActive(true);
Debug.Log("Enabled");
escapeMenuAnimator.SetTrigger("menuOn");
isMenuOpen = true;
}
else
{
escapeMenuAnimator.SetTrigger("menuOff");
StartCoroutine(EscapeMenuOff());
isMenuOpen = false;
}
}

if (escapeMenu.activeInHierarchy == true)
{
FillButton();
}

if (leaveGame.fillAmount == 1 && !gameState)
{
gameState = true;
LeaveGame();
}

if (quitGame.fillAmount == 1 && !gameState)
{
gameState = true;
QuitGame();
}
}
}

public void FillButton()
{
if (Input.GetKeyUp(KeyCode.L) && leaveGame.fillAmount >= 0)
{
leaveGame.fillAmount = 0;
}

if (Input.GetKeyUp(KeyCode.P) && quitGame.fillAmount >= 0)
{
quitGame.fillAmount = 0;
}

if (Input.GetKey(KeyCode.L) && leaveGame.fillAmount <= 1)
{
leaveGame.fillAmount += fillSpeed * Time.deltaTime;
}

else if (Input.GetKey(KeyCode.P) && quitGame.fillAmount <= 1)
{
quitGame.fillAmount += fillSpeed * Time.deltaTime;
}
}

IEnumerator EscapeMenuOff()
{
yield return new WaitForSeconds(0.5f);
escapeMenu.SetActive(false);
}

IEnumerator DisconnectAndLoad()
{
//PhotonNetwork.Disconnect();
PhotonNetwork.LeaveRoom();
while (PhotonNetwork.InRoom)
yield return null;

//SceneManager.LoadScene(0);
}

IEnumerator DisconnectAndQuit()
{
//PhotonNetwork.Disconnect();
PhotonNetwork.LeaveRoom();
while (PhotonNetwork.InRoom)
yield return null;

PhotonNetwork.Disconnect();
while (PhotonNetwork.IsConnected)
yield return null;
}

public void AppQuit()
{
Debug.Log("Quitting to the desktop");
Application.Quit();
}

public override void OnLeftRoom()
{
base.OnLeftRoom();
Debug.Log(PhotonNetwork.LocalPlayer.NickName + " has left the game");
}

public void LeaveInvoke()
{
Destroy(RoomManager.Instance.gameObject);
StartCoroutine(DisconnectAndLoad());
SceneManager.LoadScene(0);
}

public void QuitGameInvoke()
{
Destroy(RoomManager.Instance.gameObject);
StartCoroutine(DisconnectAndQuit());
Invoke("AppQuit", 0.2f);
}

public void LeaveGame()
{
if (!PV.IsMine)
return;

Debug.Log("Player Leaving The Game");

dropItem = this.GetComponent<ItemManager>();
dropWeapon = dropItem.equippedWeapon;

if (dropWeapon != null && PV.IsMine)
{
dropItem.photonView.RPC("Drop2", RpcTarget.AllViaServer, dropWeapon.transform.GetComponent<PhotonView>().ViewID);

Debug.Log("Equipped Gun Dropped");

Invoke("LeaveInvoke", 0.4f);

loadingTransition.SetActive(true);
}

else

{
Debug.Log("No Equipped Gun");

Invoke("LeaveInvoke", 0.4f);

loadingTransition.SetActive(true);
}
}

public void QuitGame()
{
if (PV.IsMine)
{
Debug.Log("Player Leaving The Game");

dropItem = this.GetComponent<ItemManager>();
dropWeapon = dropItem.equippedWeapon;

if (dropWeapon != null && PV.IsMine)
{
dropItem.photonView.RPC("Drop2", RpcTarget.AllViaServer, dropWeapon.transform.GetComponent<PhotonView>().ViewID);

Debug.Log("Equipped Gun Dropped");

Invoke("QuitGameInvoke", 0.4f);

loadingTransition.SetActive(true);
}

else

{
Debug.Log("No Equipped Gun");

Invoke("QuitGameInvoke", 0.4f);

loadingTransition.SetActive(true);
}
}
}

public void OnApplicationQuit()
{
if (PV.IsMine)
{
Debug.Log("Player Leaving The Game");

dropItem = this.GetComponent<ItemManager>();
dropWeapon = dropItem.equippedWeapon;

if (dropWeapon != null && PV.IsMine)
{
dropItem.photonView.RPC("Drop2", RpcTarget.AllViaServer, dropWeapon.transform.GetComponent<PhotonView>().ViewID);

Debug.Log("Equipped Gun Dropped");

Invoke("QuitGameInvoke", 0.4f);

loadingTransition.SetActive(true);
}

else

{
Debug.Log("No Equipped Gun");

Invoke("QuitGameInvoke", 0.4f);

loadingTransition.SetActive(true);
}
}
}

public override void OnPlayerLeftRoom(Player otherPlayer)
{
base.OnPlayerLeftRoom(otherPlayer);
//Display on the screen to other players
Debug.Log(otherPlayer.NickName + " has left the game");
StartCoroutine(SetLeaveText(otherPlayer));
int playerCount = PhotonNetwork.PlayerList.Length;
playerCount--;
}

IEnumerator SetLeaveText(Player player)
{
leaveText.text = player.NickName + " has left the game";
yield return new WaitForSeconds(1f);
leaveText.text = "";
}
}


Singleton Network Class:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using UnityEngine.SceneManagement;
using System.IO;
using Photon.Realtime;

public class RoomManager : MonoBehaviourPunCallbacks
{
public static RoomManager Instance;

private void Awake()
{
if(Instance) //Checks if another Room Manager is already in the scene
{
Destroy(gameObject); //There can be only one >:)
return;
}
DontDestroyOnLoad(gameObject); //I have the high ground
Instance = this;
}

public override void OnEnable()
{
base.OnEnable();
SceneManager.sceneLoaded += OnSceneLoaded;
}

public override void OnDisable()
{
base.OnDisable();
SceneManager.sceneLoaded -= OnSceneLoaded;

}

void OnSceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
{
if(scene.buildIndex == 1) //We're in the end game now
{
PhotonNetwork.Instantiate(Path.Combine("Photon Prefabs", "PlayerManager"), Vector3.zero, Quaternion.identity);

WeaponSpawn();
LightSwitch();
}

//if (scene.buildIndex == 0 && PhotonNetwork.IsConnected)
//{
// Launcher.Instance.OnConnectedToMaster();
//}
}

public void WeaponSpawn()
{
Debug.Log("Spawned Weapons");
PhotonNetwork.InstantiateRoomObject(Path.Combine("Photon Prefabs", "HandGun"), new Vector3(-90f, 1f, 0f), Quaternion.identity);
PhotonNetwork.InstantiateRoomObject(Path.Combine("Photon Prefabs", "HandGun"), new Vector3(-70f, 1f, 0f), Quaternion.identity);
PhotonNetwork.InstantiateRoomObject(Path.Combine("Photon Prefabs", "HandGun"), new Vector3(-100f, 1f, 0f), Quaternion.identity);
PhotonNetwork.InstantiateRoomObject(Path.Combine("Photon Prefabs", "HandGun"), new Vector3(-60f, 1f, 0f), Quaternion.identity);
}

public void LightSwitch()
{
Light[] lights = FindObjectsOfType(typeof(Light)) as Light[];
foreach (Light light in lights)
{
light.enabled = false;
}
}
}