Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by g__l · Aug 30, 2016 at 04:05 PM · c#networkingmatchmaking

Looking for basic explanation on unity matchmaker (5.4) and how to use in scripts

Having decided to do Networking through Unity over Photon due to price (if there is a better way of networking let me know) I have been trying to create a simple unity matchmaker where when a user enters the game they first look for any other match (AKA rooms / games), if there is one they join it, if there isn't one they create one. However I am struggling to find a clear explanation of how to use the unity matchmaker, so I can develop code to get my desired behavior which seems even trickier as it seems unity is changing it's networking system a lot in recent updates so I believe anything before 5.4 is currently out-of-date. The only useful thing I have found is this example code but I want to understand the system more so I don't miss any key concepts, which is likely as I am fairly beginner-ish.

So what I am asking you today is can you direct me to a clear explanation of the matchmaking system (including scripting) which is relevant to the current unity or, admittedly much harder and more time consuming, could you try to do it yourself and it will serve as future reference for others like me.

Thanks for reading, of course any answers will be greatly appreciated.

[i work in c#]

EDIT:

I understand my question is very difficult to answer so I am going to test out the example code until i get the desired behavior and post any errors which i cannot solve.

  1. I have copied the exact code (Included below for easier reference) into a script which i have attached to my network manager. But I am getting errors due to protection levels -

alt text

I have two theories on how to solve this -

  1. Changing the method accessors

  2. Not deriving the script from monobehaviour

I am currently testing them out, any advice on how to solve this would be very useful. I wonder if I should report this to unity as to me it seems to be a wrong example in unity docs which say it is updated for 5.4. Thanks.

 using UnityEngine;
 using UnityEngine.Networking;
 using UnityEngine.Networking.Match;
 using UnityEngine.Networking.Types;
 using System.Collections;
 
 public class MatchMaker : MonoBehaviour
 {
     void Start()
     {
         NetworkManager.singleton.StartMatchMaker();
     }
 
     //call this method to request a match to be created on the server
     public void CreateInternetMatch(string matchName)
     {
         CreateMatchRequest create = new CreateMatchRequest();
         create.name = matchName;
         create.size = 4;
         create.advertise = true;
         create.password = "";
 
         NetworkManager.singleton.matchMaker.CreateMatch(create, OnInternetMatchCreate);
     }
 
     //this method is called when your request for creating a match is returned
     private void OnInternetMatchCreate(CreateMatchResponse matchResponse)
     {
         if (matchResponse != null && matchResponse.success)
         {
             //Debug.Log("Create match succeeded");
 
             MatchInfo hostInfo = new MatchInfo(matchResponse);
             NetworkServer.Listen(hostInfo, 9000);
 
             NetworkManager.singleton.StartHost(hostInfo);
         }
         else
         {
             Debug.LogError("Create match failed");
         }
     }
 
     //call this method to find a match through the matchmaker
     public void FindInternetMatch(string matchName)
     {
         NetworkManager.singleton.matchMaker.ListMatches(0, 20, matchName, OnInternetMatchList);
     }
 
     //this method is called when a list of matches is returned
     private void OnInternetMatchList(ListMatchResponse matchListResponse)
     {
         if (matchListResponse.success)
         {
             if (matchListResponse.matches.Count != 0)
             {
                 //Debug.Log("A list of matches was returned");
 
                 //join the last server (just in case there are two...)
                 NetworkManager.singleton.matchMaker.JoinMatch(matchListResponse.matches[matchListResponse.matches.Count - 1].networkId, "", OnJoinInternetMatch);
             }
             else
             {
                 Debug.Log("No matches in requested room!");
             }
         }
         else
         {
             Debug.LogError("Couldn't connect to match maker");
         }
     }
 
     //this method is called when your request to join a match is returned
     private void OnJoinInternetMatch(JoinMatchResponse matchJoin)
     {
         if (matchJoin.success)
         {
             //Debug.Log("Able to join a match");
 
 
             MatchInfo hostInfo = new MatchInfo(matchJoin);
             NetworkManager.singleton.StartClient(hostInfo);
         }
         else
         {
             Debug.LogError("Join match failed");
         }
     }
 }


networkmatchmaker.png (285.1 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

225 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can i spawn my player in matchmaker using my UI? 0 Answers

'UnityEngine.Networking.Match.MatchDesc' is inaccessible due to its protection level (CS0122) (Assembly-CSharp) 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Automatic Match Joining for Networked Games 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges