Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

Unity Multiplayer 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:
    4
    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:
    2,079
    Host = Client playing on the server where both client and server are the same app instance. ;)
     
    Talal88 likes this.