Troubles with MatchMaker and CCU

Hello There,

I started a new multiplayer Project and most of I works very well.
But I have a Problem.

When I start a Host and restart the Game and trying to Start a Host again the following happens:

Other scenario: I Start the host on the Same machine and I trying to Join the Match but Unity can not find the Host.

But scine last Thursday everything works.

Here is my Code for the Matchmaking process:

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

public class MenuController : MonoBehaviour
{
    [System.Serializable]
    public struct SettingsUI
    {
        public InputField inputPlayerName;
    }
    public SettingsUI settingsUI;

    [System.Serializable]
    public struct Ui
    {
        public GameObject menu;
        public GameObject loadingScreen;
        public GameObject hostGameDialog;
        public LoadingScreen loadingScreenData;
        [System.Serializable]
        public struct SettingsUI
        {
            public InputField inputPlayerName;
        }
        public SettingsUI settingsUI;

        [System.Serializable]
        public struct Nav
        {
            public GameObject buttonHost;
            public GameObject buttonExit;
        }
        public Nav nav;

        [System.Serializable]
        public struct JoinDialog
        {
            public GameObject ui;
            public Text serverName;
            public GameObject passwordPanel;
            public InputField passwordInput;
        }
        public JoinDialog joinDialog;

    }
    public Ui ui;


    [System.Serializable]
    public struct GameSettings
    {
        public List<string> maps;

        public GameObject serverListUI;
        public GameObject serverListUIItemPrefab;

        public MatchDesc matchToJoin;

    }
    public GameSettings gameSettings;

    [System.Serializable]
    public struct ServerSettings
    {
        public InputField inputName;
        public InputField inputPasswort;
        public Dropdown inputMap;

    }
    public ServerSettings serverSettings;

    void Awake ()
    {

        Settings.Get();
        SetInput(settingsUI.inputPlayerName, Settings.playerName);

        if(PlayerPrefs.GetString("cliendId") == string.Empty || PlayerPrefs.GetString("cliendId") == "")
        {
            string pool = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string random = string.Empty;
            for(int i = 0; i < 100; i++)
            {
                random += pool[Random.Range(0, pool.Length)];
            }
            PlayerPrefs.SetString("cliendId", random);
        }
        Tools.UI.menu = ui.menu;
        Tools.UI.MenuVisible();
    }

    void Start()
    {
        serverSettings.inputMap.options.Clear();
        serverSettings.inputMap.AddOptions(gameSettings.maps);

        NetworkManager.singleton.StartMatchMaker();
    }

    public void NameSetByInput(InputField input)
    {
        Settings.playerName = input.text;
        Settings.Set();
    }
       
    void SetInput(InputField input, string value)
    {
        input.text = value;
    }

    void SetToggle(Toggle toggle, bool value)
    {
        toggle.isOn = value;
    }

    public void GetHostList()
    {

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

        ListMatchRequest request = new ListMatchRequest();
        request.includePasswordMatches = true;
        request.pageSize = 10000;
        request.nameFilter = "";
        NetworkManager.singleton.matchMaker.ListMatches(request, OnMatchList);

    }

    public void JoinDialog(MatchDesc match)
    {
       
        ui.joinDialog.ui.SetActive(true);
        ui.joinDialog.ui.GetComponent<RectTransform>().SetAsLastSibling();
        ui.joinDialog.serverName.text = match.name;

        gameSettings.matchToJoin = match;
    }

    public void JoinMatch()
    {
        if(gameSettings.matchToJoin == null)
        {
            return;
        }

        JoinMatchRequest request = new JoinMatchRequest();
        request.networkId = gameSettings.matchToJoin.networkId;
        request.password = ui.joinDialog.passwordInput.text;

        NetworkManager.singleton.matchMaker.JoinMatch(request, OnJoinMatch);

        ui.loadingScreen.SetActive(true);
        ui.loadingScreenData.text.text = Lang.GetString("Loading");
        ui.loadingScreenData.slider.value = 0.0f;
        ui.joinDialog.ui.SetActive(false);
        ui.hostGameDialog.SetActive(false);
        Tools.UI.MenuHide();
    }

    void OnJoinMatch(JoinMatchResponse res)
    {
        if(res.success)
        {
            ui.loadingScreenData.text.text = Lang.GetString("Loading");
            ui.loadingScreenData.slider.value = 0.1f;

            Utility.SetAccessTokenForNetwork(res.networkId, new NetworkAccessToken(res.accessTokenString));
            NetworkManager.singleton.StartClient(new MatchInfo(res));
        }
        else
        {
            ui.loadingScreen.SetActive(false);
            Tools.UI.MenuVisible();
        }
    }

    void OnMatchList(ListMatchResponse res)
    {
        if(res.success)
        {
            UIList<MatchDesc, ServerListItem> serverList = new UIList<MatchDesc, ServerListItem>(gameSettings.serverListUI, gameSettings.serverListUIItemPrefab, res.matches);
            serverList.UpdateList();
        }
    }

    public void StartHost()
    {
        if(NetworkManager.singleton.matchMaker == null)
        {
            NetworkManager.singleton.StartMatchMaker();
        }

        CreateMatchRequest request = new CreateMatchRequest();

        request.name = serverSettings.inputName.text;
        request.size = 16;
        request.password = serverSettings.inputPasswort.text;

        Tools.gameName = request.name;

        ui.loadingScreen.SetActive(true);
        ui.loadingScreenData.text.text = Lang.GetString("Loading");
        ui.loadingScreenData.slider.value = 0.0f;

        ui.joinDialog.ui.SetActive(false);
        ui.hostGameDialog.SetActive(false);
        Tools.UI.MenuHide();
        NetworkManager.singleton.onlineScene = serverSettings.inputMap.options[serverSettings.inputMap.value].text;

        NetworkManager.singleton.matchMaker.CreateMatch(request, OnMatchCreate);

    }

    void OnMatchCreate(CreateMatchResponse matchResponse)
    {
        if(matchResponse.success)
        {
            MatchInfo info =  new MatchInfo(matchResponse);

            ui.loadingScreenData.text.text = Lang.GetString("Loading");
            ui.loadingScreenData.slider.value = 0.1f;

            Utility.SetAccessTokenForNetwork(matchResponse.networkId, new NetworkAccessToken(matchResponse.accessTokenString));

            NetworkManager.singleton.StartHost(info);

        }
        else
        {
            ui.loadingScreen.SetActive(false);
            Tools.UI.MenuVisible();
        }
    }

    void Update()
    {
        if(Input.GetButtonDown("Menu"))
        {
            Tools.UI.MenuToggle();
        }

        if(Tools.gameController.isActive)
        {
            ui.nav.buttonHost.SetActive(false);
            ui.nav.buttonExit.SetActive(true);
        }
        else
        {
            ui.nav.buttonHost.SetActive(true);
            ui.nav.buttonExit.SetActive(false);
        }

    }

    public void Exit()
    {
        if(NetworkServer.active)
        {
            Tools.gameController.persistence.Save();
        }
        NetworkManager.singleton.client.Disconnect();
    }

    public void Quit()
    {
        Application.Quit();
    }

}

Maybe I did some mistake, but I don’t know whar should be wrong, because It worked in the Past.

Hi @SaphiBlue
We pre-debit CCU’s when you create a match, and you’re setting that to 16 in the create match request. That means your CCU count will be 16 when you create that match. This is so no join requests are denied because your game has used up all it’s CCUs.
When the host leaves it will take roughly 30 seconds for the match to time out unless everyone in the match calls DropConnection on themselves when they leave. In that case, it will take 30 seconds for your 16 CCUs to free up. If you’re using a personal license then you only have 20 CCU to play with, so you’d get denied on the next run until the first game expires.

Thank you for your quick response.

I set back the match size to 4, now I can restart the host.
But the NetworkManager.singleton.matchMaker.ListMatches(request, OnMatchList);
still results in:

JSON Response: [[UnityEngine.Networking.Match.ListMatchResponse]-success:True-extendedInfo:]-matches.Count:0
UnityEngine.Networking.Match.<ProcessMatchResponse>c__Iterator0`1:MoveNext()

there are 16 CCU now left.

the problem was:
in ther Match create request should be a request.advertise=true;

1 Like