Search Unity

Third Party PUN 2 Cant connect to master

Discussion in 'Multiplayer' started by vagelis199, Aug 12, 2021.

  1. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    182
    "Connecthing to a photon server"So I followed this tutorial

    following the tutorial, everything seems to work fine. but trying to implement the code into my code, I cannot connect to the server using
    PhotonNetwork.ConnectUsingSettings();


    As seen in the tutorial he creates a NetworkController.cs script which is like that
    Code (CSharp):
    1. using Photon.Pun;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class NetworkController : MonoBehaviourPunCallbacks
    7. {
    8.     // Start is called before the first frame update
    9.     void Start()
    10.     {
    11.         PhotonNetwork.ConnectUsingSettings();
    12.     }
    13.  
    14.     public override void OnConnectedToMaster()
    15.     {
    16.         Debug.Log("Connected to: " + PhotonNetwork.CloudRegion);
    17.  
    18.     }
    19.  
    20. }
    21.  
    The on OnConnectedToMaster() logs normaly.

    And here is my implementation
    Code (CSharp):
    1.  
    2.   public override void OnConnectedToMaster()
    3.     {
    4.         IniServer = true;
    5.         Debug.Log("Connected to: " + PhotonNetwork.CloudRegion);
    6.         PhotonNetwork.AutomaticallySyncScene = true;
    7.         PhotonNetwork.JoinRandomRoom();
    8.         Debug.Log("Connecting to room...");
    9.  
    10.  
    11.     }
    12.  
    13. void FixedUpdate()
    14.     {
    15.      
    16.         if (SceneManager.GetActiveScene().name != "MotocrossGarage")
    17.         {
    18.          
    19.                     if (!int2)
    20.             {
    21.                 PhotonNetwork.ConnectUsingSettings();
    22.                 Debug.Log("Connecthing to a photon server");
    23.                 int2 = true;
    24.  
    25.             }
    26.  
    27.  
    28.             this.GetComponent<AudioListener>().enabled = true;
    29.             if (IniServer)
    30.             {
    31.  
    32.                 if (!sceneloaded)
    33.                 {
    34.                     //SceneManager.LoadSceneAsync("BaseRace", LoadSceneMode.Additive);
    35.                     if (connectedtoserver)
    36.                     {
    37.                         this.GetComponent<AudioListener>().enabled = false;
    38.                         PhotonNetwork.LoadLevel("BaseRace");
    39.  
    40.                         //  NetwObj = Instantiate(NetworkManagerPrefab);
    41.                         NetwObj = this.transform.GetChild(1).gameObject;
    42.  
    43.                         sceneloaded = true;
    44.  
    45.  
    46.  
    47.                     }
    48.  
    49.                 }
    50.  
    51.  
    52.  
    53.  
    54.                 //        
    55.                 //            Debug.Log("Scene is not garage");
    56.  
    57.  
    58.  
    59.  
    60.  
    61.  
    62.             }//end serverinit
    63.             if (sceneloaded)
    64.             {
    65.                 if (!int1)
    66.                 {
    67.                     if (GameObject.FindGameObjectWithTag("Canvas"))
    68.                     {
    69.                         GameObject.FindGameObjectWithTag("Canvas").GetComponent<InGame_MainMenu>().Inital();
    70.  
    71.                     }
    72.                     int1 = true;
    73.                 }
    74.             }
    75.         }
    76.     }
    I get the
    Debug.Log("Connecthing to a photon server");
    log from fixed update but never the
     Debug.Log("Connected to: " + PhotonNetwork.CloudRegion)

    ; from OnConnectedToMaster

    Am I missing something?
     
  2. vagelis199

    vagelis199

    Joined:
    Jul 27, 2012
    Posts:
    182
    I left an empty
    void OnEnbaled(){
    }

    which apparently interfered with the pun callbacks. removing the function resolved the issue