"Player" not being instantiated on scene

matheussartori

New member
Hello guys.

I just created a project and made a simple scene to connect the testing users to the same room.

On the "Sandbox_Map" scene, i've followed the documentation on the scene, and characters below:
https://opsive.com/support/documentation/character-controller-pun-multiplayer-add-on/setup/scene/
https://opsive.com/support/document...oller-pun-multiplayer-add-on/setup/character/

The player isn't being instantiated when i join a room. Maybe the problem is with my menu script?


C#:
public class MainMenuHandler : MonoBehaviourPunCallbacks
    {
        [SerializeField] private GameObject _loadingPanel;
        [SerializeField] private GameObject _mainPanel;
        [SerializeField] private TMP_Text _loadingText;
        [SerializeField] private string _levelName;
        
        private const string LOADING_PANEL = "loading_panel";
        private const string MAIN_PANEL = "main_panel";

        #region Unity Callbacks

        private void Awake()
        {
            CloseMenus();
            OpenMenu(LOADING_PANEL);
        }

        private void Start()
        {
            PhotonNetwork.ConnectUsingSettings();
            _loadingText.text = "Connecting to the master server...";
        }
        
        #endregion

        #region Menu Functions

        private void OpenMenu(string menuName)
        {
            switch (menuName)
            {
                case LOADING_PANEL:
                    _loadingPanel.gameObject.SetActive(true);
                    _mainPanel.gameObject.SetActive(false);
                    break;
                case MAIN_PANEL:
                    _mainPanel.gameObject.SetActive(true);
                    _loadingPanel.gameObject.SetActive(false);
                    break;
                default:
                    throw new Exception("Invalid menu was requested by the client.");
            }
        }

        private void CloseMenus()
        {
            _loadingPanel.gameObject.SetActive(false);
            _mainPanel.gameObject.SetActive(false);
        }

        private RoomOptions GetRoomOptions()
        {
            RoomOptions roomOptions = new RoomOptions();
            roomOptions.MaxPlayers = 20;

            return roomOptions;
        }

        public void StartGame()
        {
            PhotonNetwork.JoinOrCreateRoom(
                "alpha_testing",
                GetRoomOptions(),
                new TypedLobby("alpha_lobby", LobbyType.Default)
            );
            
            PhotonNetwork.LoadLevel(_levelName);
        }

        #endregion

        #region PUN Callbacks

        public override void OnConnectedToMaster()
        {
            _loadingText.text = "Joining a lobby...";
            PhotonNetwork.JoinLobby();
            PhotonNetwork.AutomaticallySyncScene = true;
        }

        public override void OnJoinedLobby()
        {
            OpenMenu(MAIN_PANEL);
        }

        #endregion
    }

The function StartGame() is called when the button TEST_PLAY is clicked, and you move to the scene but with no players...

Any idea of what could be?

Thanks!
 

matheussartori

New member
I just solved the problem. It was not with anything related to the UFPS, it was this menu script that i created.

I wasn't waiting for the room to be ready, i just moved the PhotonNetwork.LoadLevel() to the OnJoinedRoom callback and now works fine.
 
Top