Unity 2018.2 - UNet Matchmaking only works at LAN

1k Views Asked by At

I'm trying to implement the UNET Matchmaking system based on a tutorial from Brackeys.

I already enabled the multiplayer services in my Unity account and enabled the service.

When I try to create a match and find it from another PC in my LAN, it works perfect.

When I try to create a match and find it from another PC outside of my LAN, I can't see the match in the match list.

I already searched the docs and google but didn't find anything about it.

Anyone have a clue?

By the way, here is my JoinRoom script.

The return from callback function is successful, but the list of rooms comes back empty.

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
using System;

public class JoinGame : MonoBehaviour
{
    List<GameObject> roomList = new List<GameObject>();

    [SerializeField] GameObject roomListItemPrefab;
    [SerializeField] Transform roomListParent;
    [SerializeField] Text status;
    private NetworkManager networkManager;

    void Start()
    {
        networkManager = NetworkManager.singleton;

        if (networkManager.matchMaker == null)
        {
            networkManager.StartMatchMaker();
        }

        RefreshRoomList();

    }

    public void RefreshRoomList()
    {
        ClearRoomList();
        networkManager.matchMaker.ListMatches(0, 20, "", false, 0, 0, OnMatchList);
        status.text = "Loading...";
    }

    public void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> responseData)
    {
        status.text = "";

        if (!success)
        {
            status.text = "Couldn't get room list";
            return;
        }

        responseData.ForEach(match =>
        {
            GameObject _roomListItemGO = Instantiate(roomListItemPrefab);
            _roomListItemGO.transform.SetParent(roomListParent);
            RoomListItem _roomListItem = _roomListItemGO.GetComponent<RoomListItem>();

            if (_roomListItem != null)
            {
                _roomListItem.Setup(match, JoinRoom);
            }

            //as well as setting up a callback function that will join the game
            roomList.Add(_roomListItemGO);
        });

        if (roomList.Count == 0)
        {
            status.text = "No rooms at the moment";
        }
    }

    public void JoinRoom(MatchInfoSnapshot _match)
    {
        Debug.Log($"Joining {_match.name}");
        networkManager.matchMaker.JoinMatch(_match.networkId, "", "", "", 0, 0, networkManager.OnMatchJoined);
        ClearRoomList();
        status.text = $"Joining {_match.name}...";
    }

    private void ClearRoomList()
    {
        roomList.ForEach(item =>
        {
            Destroy(item);
        });

        roomList.Clear();
    }
}
2

There are 2 best solutions below

0
On BEST ANSWER

The whole problem is related with the Unity MM servers load balancers.

My code was only working in my LAN because the server was being created in the same US region.

This happened because my LAN has a VPN with Canada.

When I connect from a PC outside of my LAN, I was being directed to another region, that was why I can't find the server created by my LAN machine.

After deploy to two computers outside of my LAN, they both can create and connect do another one server.

0
On

I actually figured out the problem. First, you have to refresh configuration and make sure that cloud configuration is in working state and Multiplayer service is enabled, sometimes it just randomly turns off. Then you should pick matchmaking server directly by naming it, for ex I'm using European server which is eu1-mm.unet.unity3d.com If you simply use mm.unet.unity3d.com it can host your game on different server than your client. And players in different servers not going to see each other. Alternatively you can start your own local server and port forward your IP, then using it as your host IP on client side. Except if you have dynamic IP then you can use services like no-ip to get static domain for your IP. I'm using this method now and plus it is free of charge.