Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

LAN multiplayer not working

Discussion in 'Netcode for GameObjects' started by ondra845, Mar 1, 2023.

  1. ondra845

    ondra845

    Joined:
    Nov 11, 2021
    Posts:
    1
    Connect Across Devices on same LAN | Unity Netcode - Quick Tutorial - YouTube
    I have followed this video, it seems that everything is working, when hosting game it shows local ip to which clients should connect. But when clients try to connect I see in debugging, that they are connecting to correct ip and after some time Error message appears that failed to connect to server. It works when two instances are ran on same PC but when on two different laptops it doesnt work.

    PS: I think there is no problem in Firewall because i allowed to acces in public and private network.


    [SerializeField] Text ipAddressHostText;
    [SerializeField] InputField ipToJoin;

    [SerializeField] string ipAddress;
    [SerializeField] UnityTransport transport;

    private void Start()
    {
    ipAddress = "0.0.0.0";
    SetIpAddress();
    }

    public void HostGame() {
    NetworkManager.Singleton.StartHost();
    GetLocalIPAddress();
    }

    public void JoinGame() {
    ipAddress = ipToJoin.text;
    SetIpAddress();
    NetworkManager.Singleton.StartClient();
    }

    public void SetIpAddress()
    {
    transport = NetworkManager.Singleton.GetComponent<UnityTransport>();
    transport.ConnectionData.Address = ipAddress;
    Debug.Log("Starting ip: " + ipAddress);
    }

    public string GetLocalIPAddress()
    {
    var host = Dns.GetHostEntry(Dns.GetHostName());
    foreach (var ip in host.AddressList)
    {
    if (ip.AddressFamily == AddressFamily.InterNetwork)
    {
    ipAddressHostText.gameObject.SetActive(true);
    ipAddressHostText.text = "IP for hosting: " + ip.ToString();
    ipAddress = ip.ToString();
    Debug.Log("local ip: " + ip);
    return ip.ToString();
    }
    }
    throw new System.Exception("No network adapters with an IPv4 address in the system!");
    }
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,350
    does each client have correct server ip? (where they connect)

    and tried with firewall completely disabled?
     
  3. Giga500Var

    Giga500Var

    Joined:
    Nov 14, 2019
    Posts:
    1
    You, probably do not have Allowed Remote Connections (by default the option is unchecked).
    In that YouTube video an older version of Unity Transport is used. It does not have the toggle. So, Remote Connections are always Allowed.

    upload_2023-6-28_17-25-11.png
     
    Last edited: Jun 28, 2023
    ba55yunky likes this.