Player can't leave the room when automaticallySyncScene is set to true.

Options
Player can't leave the room when automaticallySyncScene is set to true.

My code:
MenuController:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class MenuController : MonoBehaviour
{
[SerializeField] private string VersionName = "0.01";
[SerializeField] private GameObject usernameMenu;
[SerializeField] private GameObject MainMenu;
[SerializeField] private InputField usernameInput;
[SerializeField] private InputField JoinGameInput;
[SerializeField] private InputField CreateGameInput;
[SerializeField] private GameObject StartButton;
public string Map = "Game";
// Start is called before the first frame update
private void Start()
{
usernameMenu.SetActive(true);

}

private void Awake()
{
PhotonNetwork.ConnectUsingSettings(VersionName);
PhotonNetwork.autoCleanUpPlayerObjects = true;
PhotonNetwork.automaticallySyncScene = true;

}

// Update is called once per frame
void Update()
{

}

private void OnConnectedToMaster()
{
PhotonNetwork.JoinLobby(TypedLobby.Default);
Debug.Log("Connected");
}

public void ChangeUserName()
{
if(usernameInput.text.Length >= 2)
{
StartButton.SetActive(true);
}
else
{
StartButton.SetActive(false);
}
}

public void SetUsername()
{
usernameMenu.SetActive(false);
PhotonNetwork.playerName = usernameInput.text;
}

public void CreateGame()
{
PhotonNetwork.CreateRoom(CreateGameInput.text, new RoomOptions() { maxPlayers = 5 }, null);
}

public void JoinGame()
{
RoomOptions Room = new RoomOptions();
Room.maxPlayers = 5;
PhotonNetwork.JoinOrCreateRoom(JoinGameInput.text, Room, TypedLobby.Default);

}

private void OnJoinedRoom()
{
PhotonNetwork.LoadLevel(Map);

}

public void HandleInputData(int value)
{
if(value == 0)
{
Map = "Game";
}

if(value == 1)
{
Map = "Game2";
}
}
}

Disconnect code:
public void DisconnectButton()
{
PhotonNetwork.Disconnect();
PhotonNetwork.LoadLevel("SampleScene");
}

Comments

  • Yoethan64
    Options
    @Tobias can I draw your attention in this case?
  • Tobias
    Tobias admin
    edited April 2021
    Options
    You can try. But it usually doesn't make much of a difference. ;)

    We don't debug code and this is too much to check by skimming it.
    You can always leave a room, cause that is not tied in any way with the scene and AutomaticallySyncScene. That setting just makes sure that when the Master Client loads another scene the others have a chance to know and load the same (while disabling the message queue temporarily).

    Maybe your code triggers loading the scene all the time, even though you mean to load another? Then PhotonNetwork.LeaveRoom() should do?
  • Yoethan64
    Options
    thanks for the help.