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

host name in unity lobby

Discussion in 'Netcode for GameObjects' started by langqing429, Nov 7, 2022.

  1. langqing429

    langqing429

    Joined:
    Aug 6, 2022
    Posts:
    4
    I have no idea how to get a host name of the lobby in unity netcode. help
     
  2. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    136
    You mean the player who created the lobby? He is the first person in the lobby players list I think.
     
    langqing429 likes this.
  3. Niter88

    Niter88

    Joined:
    Jul 24, 2019
    Posts:
    112
    Inside a NetworkBehaviour there is a variable called IsHost.
    You can check if a player is a host and then store any variable you want to identify the player.
    Code (CSharp):
    1. string hostName = "";
    2.     public override void OnNetworkSpawn()
    3.     {
    4.         base.OnNetworkSpawn();
    5.         if (IsHost)
    6.         {
    7.             hostName = "name";
    8.         }
    9.     }
    There is also
    NetworkManager.ConnectedHostname;
    but I couldn't find any documentation on what it does. Only: https://docs-multiplayer.unity3d.com/netcode/current/api/Unity.Netcode.NetworkManager/index.html