Search Unity

Client is both the host and the client while host is only the host - Unity Relay

Discussion in 'Multiplayer' started by Talal88, Mar 5, 2023.

  1. Talal88

    Talal88

    Joined:
    Jun 25, 2021
    Posts:
    7
    When placing this conditional in Update() of the player script, the host shows: "IsClient 0",

    and the client shows both: "IsClient 0", "IsClient 1":

    Code (CSharp):
    1. if (IsClient)
    2.    {
    3.        Debug.Log("IsClient " + OwnerClientId);
    4.    }
    Any ideas why the client is both the host and the client at the same time?


    For reference, this is the join code inside my relay script:


    Code (CSharp):
    1.  
    2. [ConsoleMethod( "JoinRelay", "Joins the relay" )]
    3.  
    4. public static async void JoinRelay(string joinCode)
    5.     {
    6.         try {
    7.             Debug.Log("Joining Relay with " + joinCode);
    8.             JoinAllocation joinAllocation = await RelayService.Instance.JoinAllocationAsync(joinCode);
    9.  
    10.             RelayServerData relayServerData = new RelayServerData(joinAllocation, "dtls");
    11.  
    12.             NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(relayServerData);
    13.  
    14.             NetworkManager.Singleton.StartClient();
    15.  
    16.         } catch (RelayServiceException e) {
    17.             Debug.Log(e);
    18.         }
    19.    
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,956
    Host = Client playing on the server where both client and server are the same app instance. ;)
     
    Talal88 likes this.