Search Unity

Does the host now need to join as well?

Discussion in 'Netcode for GameObjects' started by jdell64, Apr 21, 2022.

  1. jdell64

    jdell64

    Joined:
    Mar 15, 2017
    Posts:
    13
    I have some code Utilizing NGO transport and relay. I followed along the demos by Dilmer Valecillos (https://www.youtube.com/playlist?list=PLQMQNmwN3FvyyeI1-bDcBPmZiSaDMbFTi). I was having some timeout issues so I updated my packages. Now, the when the host starts, it never connects as a client.
    Code (CSharp):
    1.  
    2.  
    3. public async void StartCreateGame()
    4. {
    5. // sign in, create allocation, set transport's relayServerData, and get the join code
    6.     await RelayManager.Instance.SetupRelay();
    7.  
    8.     if (NetworkManager.Singleton.StartHost())
    9.     {
    10.         Debug.Log("Host started..."); // I see this message
    11.     }
    12.     else
    13.     {
    14.         Debug.Log("Unable to start host...");
    15.     }
    16.     joinCode = RelayManager.Instance.HostData.JoinCode;
    17.    
    18. }
    19.  
    In another script (MultiplayerPlayersManager), I have the OnClientConnectedCallback:

    Code (CSharp):
    1.  NetworkManager.Singleton.OnClientConnectedCallback += (id) =>
    2.             {
    3.                 Debug.Log("Client connected Callback"); // Never fires for the host
    4.                 if (IsServer)
    5.                     playersInGame.Value++;
    6.  
    7.                 // playerIdsInGame.Add(id);
    8.                 Debug.Log($"players in game: {playersInGame.Value}"); // Host sees "1" after the other device joins, the other device sees 0
    9.  
    10.                 // AnswerData.Add(new MultiplayerGameData(id));
    11.                 // UpdateMultiplayerClientIdCache();
    12.  
    13.                 if (playersInGame.Value == RelayManager.DefaultNumberOfMaxPlayers) //2 players max
    14.                 {
    15.                     // todo: check client versions first
    16.                     // SetOtherPlayerId();
    17.                     if (!IsSpawned)
    18.                     {
    19.                         Debug.LogError("not spawned");
    20.                     }
    21.  
    22.                     // send signal
    23.                     SendPregameSignalClientRpc();
    24.                 }
    25.             };
    26.  
    Has Relay, NGO, or Transport changed how the host is supposed to connect?