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 Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    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:
    96
    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:
    89
    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