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

Matchmaking - DestroyMatch Does Not Do Anything

Discussion in 'Multiplayer' started by Matt-Cranktrain, Sep 29, 2015.

  1. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    129
    Hi, I'm using Unity Pro 5.2.1f1 and trying to implement a matchmaking lobby.

    I use DestroyMatch to try to remove a match. In the console I see that this API request has been sent to the server:



    But the match is not removed from the list, and the callback is never triggered.

    This is how I'm destroying a match:

    Code (csharp):
    1. public void DestroyHostedMatch() {
    2.   if (IsHostingMatch) {
    3.   networkMatch.DestroyMatch(hostedMatchNetID, OnDestroyHostedMatch);
    4.   }
    5. }
    6.  
    7. public void OnDestroyHostedMatch(BasicResponse destroyMatchResponse) {
    8.   if (destroyMatchResponse.success) {
    9.   print("The match has been destroyed");
    10.   } else {
    11.   print("Destroying match failed.");
    12.   }
    13. }
    14.  
    The hostedMatchNetID id is an ID I save when the host creates the match.

    I can create and join matches just fine, what is going on with DestroyMatch? Like I said, the OnDestroyHostedMatch callback is never triggered, so I don't even get an error response back.

    What is going on?
     
    Reisender likes this.
  2. JeremyUnity

    JeremyUnity

    Unity Technologies

    Joined:
    Mar 4, 2014
    Posts:
    147
    Hmm, that all looks perfectly correct to me at first glance. I'll PM you to collect some additional info so i can investigate if that's ok.
     
  3. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
  4. JeremyUnity

    JeremyUnity

    Unity Technologies

    Joined:
    Mar 4, 2014
    Posts:
    147
    Thanks for the info Capn_Andy.

    Sorry for the delayed response on this issue, I'm still looking into this.
    Are you guys able to do DropConnection requests? Though the docs are pretty bad about this flow right now, DropConnection is intended to be used by each client as they leave a match and when the last one leaves the match will be automatically cleaned up immediately. DestroyMatch is more an error recovery function where you know the match should be terminated immediately but for whatever reason cant wait for all clients to voluntarially leave.
     
  5. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    Just switched over to this and it does indeed work better than destroying the MatchMaker object every time ;)

    Code (CSharp):
    1.     void OnMatchmakerDrop(BasicResponse response) {
    2.         Debug.Log ("Dropped connection; "+response.ToString ());
    3.     }
    4.  
    5.     void Disconnect() {
    6.         if (matchMaker != null && matchInfo != null) {
    7.         matchMaker.DropConnection(matchInfo.networkId, matchInfo.nodeId, OnMatchmakerDrop);
    8.         }
    9.  
    Similar issue as before though, the "OnMatchmakerDrop" callback is never called... I'd at least expect an error in the callback...

    Edit: Looks like the callback is called but only if you wait for it; if you start sending other commands to the matchMaker it'll cancel the callback.
     
    Last edited: Oct 2, 2015
    JeremyUnity likes this.
  6. JeremyUnity

    JeremyUnity

    Unity Technologies

    Joined:
    Mar 4, 2014
    Posts:
    147
    Thanks for the info. I'm working on improving this flow currently, i'll look into the multiple open requests not returning too.
     
  7. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    Thanks Jeremy. FYI, if you're working on this DropConnection stuff, I'm getting the following logs when I start a server/client (host), and put up a matchmaker opening, then disconnect before any clients connect:

    Code (CSharp):
    1. System.FormatException: FAILURE Returned from server: Failed: client not found for appId=REDACTED, check to see if it is still connected to the match
    2.   at UnityEngine.Networking.Match.Response.Parse (System.Object obj) [0x00000] in <filename unknown>:0
    3.   at UnityEngine.Networking.Match.NetworkMatch+<ProcessMatchResponse>c__Iterator0`1[UnityEngine.Networking.Match.BasicResponse].MoveNext () [0x00000] in <filename unknown>:0
    4. UnityEngine.Networking.Match.<ProcessMatchResponse>c__Iterator0`1:MoveNext()
    5.  
     
    Anisoropos and JeremyUnity like this.
  8. Dudledok

    Dudledok

    Joined:
    Oct 24, 2013
    Posts:
    110
    Posting in this thread from mine so it's in one place.

    I assume you mean DropConnection not DropMatch, if so I have the same issue with DropConnection. See below I simply swapped it in for DestroyMatch.
    Code (CSharp):
    1.     public void DestroyMatch()
    2.     {
    3.         networkMatch.DropConnection(matchInfo.networkId, matchInfo.nodeId, OnMatchDestroyed);
    4. //        networkMatch.DestroyMatch(matchInfo.networkId, OnMatchDestroyed);
    5.     }
    6.  
    7.     public void OnMatchDestroyed(BasicResponse destroyMatchResponse)
    8.     {
    9.         Debug.Log("Cancel success: " + destroyMatchResponse.success);
    10.     }
    The call back is never called and networkMatch becomes null so I still get a missing reference exception when trying to host another match.
    Also see my older thread: http://forum.unity3d.com/threads/how-to-use-networkmatch-properly.355254/

    Here you can see that creating a new matchmaking object has its own issue. I've also tried calling StopMatchmaker on the NetworkManager object and then StartMatchmaker but I get the same issue:
    Code (CSharp):
    1. host id out of bound id {-1} max id should be greater 0 and less than {2}
    2. UnityEngine.Networking.NetworkServer:Listen(MatchInfo, Int32)
    3. NetManagerHud:MatchCreated(CreateMatchResponse) (at Assets/Scripts/Networking/NetManagerHud.cs:78)
    4. UnityEngine.Networking.Match.<ProcessMatchResponse>c__Iterator0`1:MoveNext()
    5.  
     
  9. JeremyUnity

    JeremyUnity

    Unity Technologies

    Joined:
    Mar 4, 2014
    Posts:
    147
    It sounds like the flow you're using to recycle the match has issues. In general when starting a new match it's best destroy your entire state and start from scratch if you're hosting a new match.

    I'm adding an auto connection drop to a future update of unity, and i call it from the OnClientDisconnect handler in NetworkManager, if the matchmaker and matchinfo are not null and have a valid network id and node id.
     
  10. Dudledok

    Dudledok

    Joined:
    Oct 24, 2013
    Posts:
    110
    What is the proper way to do that then?

    Currently if I'm hosting a match and I click the back button I call my own DestroyMatch function:
    Code (CSharp):
    1.     public void DestroyMatch()
    2.     {
    3.         networkMatch.DropConnection(matchInfo.networkId, matchInfo.nodeId, OnMatchDestroyed);
    4. //        networkMatch.DestroyMatch(matchInfo.networkId, OnMatchDestroyed);
    5.         manager.StopMatchMaker();
    6.     }
    I'm calling DropConnection and/or DestroyMatch (tried both) and StopMatchmaker.
    If I then try and host again by calling StartMatchmaker which creates a new NetworkMatch component, assigning that to a variable and setting the program app ID, creating a match request and then calling CreateMatch with that request, the callback is called but I get the following error:
    Code (CSharp):
    1.         if (createMatchResponse.success)
    2.         {
    3.             Utility.SetAccessTokenForNetwork(createMatchResponse.networkId, new NetworkAccessToken(createMatchResponse.accessTokenString));
    4.             NetworkServer.Listen(new MatchInfo(createMatchResponse), 9000); //triggers error
    5.             manager.StartHost(new MatchInfo(createMatchResponse)); //triggers error
    6.             matchInfo = new MatchInfo(createMatchResponse);
    7.         }
    I had a look around as others have had that error and it seems to be triggered when the host id is in use by another function, and I can see in my code that the callback for DropConnection or DestroyMatch is never called. You can see I used the same callback but neither of these actually call the callback:
    Code (CSharp):
    1.     public void OnMatchDestroyed(BasicResponse destroyMatchResponse)
    2.     {
    3.         Debug.Log("Cancel success: " + destroyMatchResponse.success);
    4.     }
    So perhaps because it is still trying to call this callback that causes the error?
     
    Last edited: Oct 7, 2015
  11. JeremyUnity

    JeremyUnity

    Unity Technologies

    Joined:
    Mar 4, 2014
    Posts:
    147
    It sounds like there's likely an issue with holding on to state inside network manager in the version you're on when recycling, at least with the flow you have. It's hard to tell because i don't have the full source for your project.
    If possible, please file a bug and attach a project reproducing the issue with that bug.
     
    Dudledok likes this.
  12. Dudledok

    Dudledok

    Joined:
    Oct 24, 2013
    Posts:
    110
    I updated to 5.1.4 and calling NetworkServer.Listen still triggers the error, but StartHost doesn't, so commenting out Listen it works fine after an initial test.
    The OnMatchDestroyed callback still isn't called however.
     
  13. JeremyUnity

    JeremyUnity

    Unity Technologies

    Joined:
    Mar 4, 2014
    Posts:
    147
    There were a lot of fixes as time went on after our initial release in 5.1. In general i'd recommend being on the latest 5.2 if possible to get the most up to date code for Unity Multiplayer.
    With that said there's no specific fix for the issue you're seeing with the callback not being called in 5.2 so if you're down to just that issue i'm guessing moving up wont fix that.
     
  14. Dudledok

    Dudledok

    Joined:
    Oct 24, 2013
    Posts:
    110
    I tried 5.2.1 but had the same issue I think (the original one!), I'll try again though. I had other issues with 5.2 which made it not worth using, such as all UI Text became black and couldn't be changed, but that's a separate issue. Thanks for the quick responses.
     
  15. Reisender

    Reisender

    Joined:
    Jun 26, 2014
    Posts:
    35
    Same issue here... callback is never triggered. Using Unity 5.2.1f1.