Search Unity

MLAPI Instantly Discconecting Photon Transport OnClientConnect

Discussion in 'Netcode for GameObjects' started by StrawCowboy, Jul 22, 2021.

  1. StrawCowboy

    StrawCowboy

    Joined:
    Apr 13, 2017
    Posts:
    1
    I'm able to host a game, but I can't for the life of me get a player to be able to join, everything is set up correctly, and that's being reflected on my dashboard, but they just won't connect (Yup, they have the same room name and they're in the same region). If anyone would be able to hold my hand through this that'd be amazing.

    Here's my connection code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using MLAPI;
    5. using MLAPI.Connection;
    6. using MLAPI.Messaging;
    7. using MLAPI.Spawning;
    8. using MLAPI.Transports.UNET;
    9. using MLAPI.SceneManagement;
    10. using UnityEngine.SceneManagement;
    11. using UnityEngine.UI;
    12.  
    13. public class ConnectionManager : NetworkBehaviour
    14. {
    15.     public GameObject connectButtonPanel;
    16.  
    17.     public string ipAddress;
    18.  
    19.     UNetTransport transport;
    20.  
    21.     public Camera lobbyCamera;
    22.     public Transform spawnPoint;
    23.  
    24.     public GameObject errorPanel;
    25.  
    26.     public MLAPI.Transports.PhotonRealtime.PhotonRealtimeTransport photonRealtimeTransport;
    27.  
    28.     private void Update()
    29.     {
    30.         if (Input.GetKeyDown(KeyCode.Escape))
    31.         {
    32.             errorPanel.SetActive(false);
    33.         }
    34.     }
    35.  
    36.     public void StartHostPhoton()
    37.     {
    38.         //SceneManager.LoadScene("Main");
    39.        
    40.         var transp = photonRealtimeTransport;
    41.  
    42.      
    43.         transp.RoomName = Random.Range(10000, 99999).ToString();
    44.         ipAddress = transp.RoomName;
    45.  
    46.         NetworkManager.Singleton.StartHost();
    47.  
    48.         Debug.Log(NetworkManager.Singleton.IsClient);
    49.         Debug.Log(NetworkManager.Singleton.isActiveAndEnabled);
    50.         Debug.Log(NetworkManager.Singleton.IsConnectedClient);
    51.         Debug.Log(NetworkManager.Singleton.IsHost);
    52.         Debug.Log(NetworkManager.Singleton.NetworkConfig);
    53.  
    54.         NetworkSceneManager.SwitchScene("Lobby");
    55.     }
    56.  
    57.     public void StartClientPhoton()
    58.     {
    59.         try
    60.         {
    61.             //SceneManager.LoadScene("Main");
    62.             var transp = photonRealtimeTransport;
    63.  
    64.             Debug.Log(ipAddress);
    65.             transp.RoomName = ipAddress;
    66.  
    67.             NetworkManager.Singleton.StartClient();
    68.  
    69.             Debug.Log(NetworkManager.Singleton.IsClient);
    70.             Debug.Log(NetworkManager.Singleton.isActiveAndEnabled);
    71.             Debug.Log(NetworkManager.Singleton.IsConnectedClient);
    72.             Debug.Log(NetworkManager.Singleton.IsHost);
    73.             Debug.Log(NetworkManager.Singleton.NetworkConfig);
    74.             Debug.Log(transp.RoomName);
    75.             Debug.Log(NetworkManager.Singleton.LocalClientId);
    76.         }
    77.         catch (System.Exception ex)
    78.         {
    79.             Debug.Log(ex);
    80.         }
    81.        
    82.     }
    83.  
    84.  
    85.     public void IPAddressChanged(string newAddress)
    86.     {
    87.         this.ipAddress = newAddress;
    88.     }
    89. }
    90.  
    I've attached the code and the error log below(?)
     

    Attached Files:

  2. korinVR

    korinVR

    Joined:
    Jul 7, 2012
    Posts:
    34
  3. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
    Sorry I must have missed this thread. I looked through the editor log and it looks like the MLAPI host is disconnecting the client immediately. I don't think this is related to the issue korinVR linked. As long as you build / run / use the editor on the same device it should work totally fine.

    I think what's happening here is that the connection approval is disconnecting the player immediately. Did you check whether you are able to connect when using an IP based transport such as UNet?