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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

MatchMaker issues

Discussion in 'Multiplayer' started by Vennril, Jun 26, 2015.

  1. Vennril

    Vennril

    Joined:
    Jul 12, 2014
    Posts:
    7
    While working with the MatchMaker (NetworkMatch), I've noticed a lot of issues creating and joining matches. Tested with both 5.1.1f1 and 5.1.1p1.

    [A sample project is attached below, but all you need is a NetworkManager (or NetworkLobbyManager) and a NetworkManagerHUD. Don't forget to set your Cloud Project ID in the Player Settings.]

    Here are some test cases with 2 Clients:

    a) Client 1 creates an internet match, stops the Match Maker, starts the Match Maker again, and creates a new, second internet match.

    Error: host id out of bound id {-1} max id should be greater 0 and less than {1}
    UnityEngine.Networking.Match.<ProcessMatchResponse>c__Iterator0`1:MoveNext()
    Error: Host doesn't exist
    UnityEngine.Networking.Match.<ProcessMatchResponse>c__Iterator0`1:MoveNext()


    The new match will be created regardless, but when Client 2 tries to join, he gets a timeout.

    b) Client 1 creates an internet match, stops the Match Maker, starts the Match Maker again, goes to "Find Internet Match" and joins the match he just created.

    Error: ArgumentException: An element with the same key already exists in the dictionary.
    System.Collections.Generic.Dictionary`2[UnityEngine.Networking.Types.NetworkID,UnityEngine.Networking.Types.NetworkAccessToken].Add (NetworkID key, UnityEngine.Networking.Types.NetworkAccessToken value) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)


    This probably happens due to the OnMatchJoined callback inside the JoinMatch() call, which always tries to set an access token.

    c) Client 1 creates an internet match and leaves.
    Client 2 finds that (now empty) match and tries to join. Result: Timeout.

    Conclusion: Apparently, the ONLY way to get 2 Clients in the same match together is, if one client creates a match (without ever going back), and the other client joins (and also never goes back). If any involved client exits the lobby, they won't be able to get together again. Unless they restart the game and start over.

    Any info or suggestions are much appreciated.
     

    Attached Files:

    Anisoropos and bumbumzz like this.
  2. aspiering

    aspiering

    Joined:
    Aug 29, 2014
    Posts:
    12
    So what I gather is the old match never gets destroyed, in looking at what the NetworkManager does when you call StopMatchmaker it destroys the object but doesn't call DestroyMatch so what will happen is it will create a match that is already created because the old one already exists.

    I have not been able to get the DestroyMatch function to work properly at all. I have posted several times about it with no real information about how its suppose to work.
     
    bumbumzz likes this.
  3. Vennril

    Vennril

    Joined:
    Jul 12, 2014
    Posts:
    7
    Issue (a) has been fixed in 5.1.1p2 - Hooray.

    Baby steps.
     
  4. wontonst

    wontonst

    Joined:
    Dec 29, 2013
    Posts:
    6
  5. aspiering

    aspiering

    Joined:
    Aug 29, 2014
    Posts:
    12
    So here is my issue, even in following that guide I get the following error on my android device when I try and create a match.

    I have yet to figure out how to resolve this because its been a constant issue since day one. I am setting the AppId etc..
     
  6. wontonst

    wontonst

    Joined:
    Dec 29, 2013
    Posts:
    6
    All I can say is matchmaking has some pretty serious issues that need to be addressed. I have an issue of my own now :(

    I'm testing on three instances: Unity editor, Mac native app, and Android app.
    I can create a game and have another client join, no problem.
    The issue arises when 1 instance hosts, another instance joins that host, and the last instance hosts. The third instance hosting gets the dreaded host id out of range bug.
    I can restart the third instance to try again, use NetworkManagerHUD, etc, all lead to the same error.

    This reminds me, even when all my clients have been shut down for a hours, when I look up my CCU usage, it always says 2/100.

    If an engineer could help us out, I'll update the guide with the new findings.
     
  7. wontonst

    wontonst

    Joined:
    Dec 29, 2013
    Posts:
    6
    Also, what OnXXX function gets called on User2 when

    User1 hosts
    User2 joins User1's match
    User1 crashes shortly afterwards

    I get the header warnings on User2 but I can't find the function that gets called. I'd expect it to be OnClientError or OnClientDisconnect but those only get called after the game starts.
     
  8. aspiering

    aspiering

    Joined:
    Aug 29, 2014
    Posts:
    12
    So I have figured out my issue, So I had the following code piece,

    Code (CSharp):
    1. CreateMatchRequest create = new CreateMatchRequest();
    2. create.name = SystemInfo.deviceName;
    3. create.size = 3;
    4. create.advertise = true;
    5. create.password = "";
    6.  
    7. UnityMatchmaking.Instance.MasterServerConnection.CreateMatch(create, OnMatchCreate);
    So SystemInfo.deviceName on most android devices comes back as "<Unknown>" this value causes issues with the CreateMatchRequest name field I am going to assume stuff is not escaped correctly when the web request is made. Once I provided a legit string I was able to create games on my device.
     
  9. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    Filed bug 712934 on this
     
  10. mrm83

    mrm83

    Joined:
    Nov 29, 2014
    Posts:
    343
    Any updates on B? Or how to fix it?
    I am getting the exact same thing on 5.3.4
     
    glitchers likes this.
  11. CGDever

    CGDever

    Joined:
    Dec 17, 2014
    Posts:
    154
    This is a huge issue where the problem will be solved (???
     
  12. Gorgor

    Gorgor

    Joined:
    Apr 28, 2012
    Posts:
    51
    Yes, this bug is still around now after nearly a year of reporting? Is this even possible?
     
    glitchers likes this.
  13. svendkiloo

    svendkiloo

    Joined:
    Dec 2, 2014
    Posts:
    11
    I'm seeing the same issue. I'm also seeing this, similar issue:

    Player A creates game. Player B joins the game. I later call these:
    Code (CSharp):
    1.  
    2.             if (Network.connections.Length == 1)
    3.             {
    4.                 Network.CloseConnection(Network.connections[0], true);
    5.             }
    6.             else
    7.             {
    8.                 foreach (NetworkPlayer connection in Network.connections)
    9.                 {
    10.                     Network.CloseConnection(connection, true);
    11.                 }
    12.             }
    13.             NetworkManager.singleton.StopClient();
    14.             NetworkManager.singleton.StopHost();
    15.             NetworkManager.singleton.StopMatchMaker();
    16.             Network.Disconnect();
    17.             SceneManager.LoadScene("main");
    18.  
    After the scene has reloaded Player A can create another game, and player B can join. Works as many times as I like. But if, instead, Player B tries to create a game, there's this error:
    EDIT:
    Also, if Player A creates a game, but doesn't wait for Player B to join, but resets by calling the above code, and then tries to create another game, I get the
    error in
    as well.
     
    Last edited: Jun 1, 2016
    glitchers likes this.
  14. glitchers

    glitchers

    Joined:
    Apr 29, 2014
    Posts:
    64
    I am still having this issue (B) in 5.3.5f1.