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
-1
Question by Dudicus · Jul 13, 2017 at 02:13 AM · networkinglobbymatchmaking

Cannot start Matchmaking online game

I am working on experimenting with Matchmaking services and I can't get this code to work. I got this code from the docs and I am trying to use it to link a "Join Game" and "Create Game" to the respective functions. There are no errors when I run this with another build. (For both functions) And in the Console/Debug it says the match has been created/joined so I am just wondering how to start the game. I am using this as a lobby with Lobby. Should I call a scene change and if I do will both players still connect?

 using UnityEngine;
 using UnityEngine.Networking;
 using UnityEngine.Networking.Match;
 using System.Collections.Generic;
 
 public class GameLoader : MonoBehaviour
 {
     void Start()
     {
         NetworkManager.singleton.StartMatchMaker();
     }
 
     //call this method to request a match to be created on the server
     public void CreateInternetMatch(string matchName)
     {
         NetworkManager.singleton.matchMaker.CreateMatch(matchName, 2, true, "", "", "", 0, 0, OnInternetMatchCreate);
     }
 
     //this method is called when your request for creating a match is returned
     private void OnInternetMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo)
     {
         if (success)
         {
             Debug.Log("Create match succeeded");
 
             MatchInfo hostInfo = matchInfo;
             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, 10, matchName, true, 0, 0, OnInternetMatchList);
     }
 
     //this method is called when a list of matches is returned
     private void OnInternetMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matches)
     {
         if (success)
         {
             if (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(matches[matches.Count - 1].networkId, "", "", "", 0, 0, 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(bool success, string extendedInfo, MatchInfo matchInfo)
     {
         if (success)
         {
             Debug.Log("Able to join a match");
 
             MatchInfo hostInfo = matchInfo;
             NetworkManager.singleton.StartClient(hostInfo);
         }
         else
         {
             Debug.LogError("Join match failed");
         }
     }
 }
 

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

95 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

Related Questions

[Multiplayer] Lobby/Staging/Matchmaking flow: Quickstart using NetworkLobbyManager? 2 Answers

Custom Lobby - Ready to begin message for each player 0 Answers

Unity Matchmaking not working on different routers. 1 Answer

How to create a matchmaking lobby 0 Answers

[Multiplayer] Should I use NetworkManager.Singleton or [SerializeField] a NetworkManager gameObj with NetworkManager component in lobby? 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