Search code examples
network-programmingunity-game-engineunity-networkingunity3d-unet

Unity: Local (LAN) MatchMaking error


I'm trying to create a simple Multiplayer game. I have setup a matchmaking system and it works fine while the device is connected with the internet i.e an online lobby is successfully created. But when i try to create a lobby on local network which does not have internet access, nothing happens.

Here is the code that i use for hosting the game:

void Start()
{
    netManager = NetworkManager.singleton;
    if(netManager.matchMaker == null)
    {
        netManager.StartMatchMaker();
    }

    roomName = "MyGameRoom";
    roomSize = 12;
}

public void CreateRoom()
{
    if (roomName != "" && roomName != null)
    {
        Debug.Log("Creating Room:" + roomName);
        netManager.matchMaker.CreateMatch(roomName, roomSize, true, "", "", "", 0, 0, netManager.OnMatchCreate);
    }
}

Now if the device is connected to the internet, the game is hosted successfully. But if the device is connected to a wifi which has no internet service, nothing happens when the CreateRoom method is called.

The CreateRoom() method is linked with a onClick event of a button.

I'm new to unity networking, hope someone can point out what I'm doing wrong. Thanks.


Solution

  • The basic MatchMaking service is based on connecting to unity MatchMaker server (https://mm.unet.unity3d.com) and this server is located on the internet, which means you can't connect to It if you are not connected to the internet. The solution is to use the NetworkDiscovery which let your server send broadcast messages over the network so clients can "hear" the broadcast and then connect to the sender. If you want a sample check this thread.