DisconnectedByServerLogic when Instantiate player

Options
vemer
vemer

Hello,

When i try to instantiate the master client player using the PhotonNetwork.Instantiate , i get disconnected from the server a few seconds after, with the DisconnectedByServerLogic cause.

My scene is very simple:


In this NetworkManager object i have the NetworkManager.cs script, where i implemented the connection, room creation and instantiate logic.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
using ExitGames.Client.Photon;


public class NetworkManager : MonoBehaviourPunCallbacks
{
    public GameObject PlayerPrefab;


    void Awake()
    {
        // #Critical
        // this makes sure we can use PhotonNetwork.LoadLevel() on the master client and all clients in the same room sync their level automatically
        PhotonNetwork.AutomaticallySyncScene = true;
    }


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


    public override void OnDisconnected(DisconnectCause cause)
    {
        Debug.LogWarningFormat("PUN Basics Tutorial/Launcher: OnDisconnected() was called by PUN with reason {0}", cause);
    }


    public void CreateRoom()
    {
        RoomOptions roomOptions = new RoomOptions();
        roomOptions.MaxPlayers = 5;


        PhotonNetwork.JoinOrCreateRoom("qewqewq", roomOptions, TypedLobby.Default);
    }


    public override void OnConnectedToMaster()
    {
        CreateRoom();
    }


    public override void OnJoinedRoom()
    {
        PhotonNetwork.Instantiate("Player", new Vector3(0f,5f,0f), Quaternion.identity);
    }


    void Connect()
    {
        if (!PhotonNetwork.IsConnected)
        {
            Debug.Log("Connecting Photon");
            PhotonNetwork.ConnectUsingSettings();
            PhotonNetwork.GameVersion = "1";
        }
    }
}

I've tested the "PunBasics-Tutorial" demo project that is used on the tutorial: 0 - Introduction | Photon Engine, and the problem stills the same: when the game scene is loaded, the player is instantiated and then after a few seconds, i'm disconnected from the server by the DisconnectedByServerLogic.

Comments

  • vemer
    Options

    Nevermind. I was using a Fusion cloud server instead of a PUN. Now that i created a PUN server on the dashboard it worked.


    Sorry for the incovinience.

  • Tobias
    Options

    Thanks for the update and glad you found this out.

This discussion has been closed.