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 /
  • Help Room /
avatar image
0
Question by newbienoob · Feb 02, 2017 at 05:54 AM · networkinglisterror messagematchmaking

Object reference not set without object? Calling ListMatches and getting this error

NullReferenceException: Object reference not set to an instance of an object NetWorkingServer.OnGUI () (at Assets/Scripts/General/Networking/NetWorkingServer.cs:40)

It is a basic lobby/hud setup i am trying and I am getting this error when I press the button to search for games/ListMatches. I should be getting the 'no matches found messages' instead i get this error which i am super confused about, probably something simple i am missing here. edit: the public objects have been set in the inspector so its not that.

 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.Networking;
 using UnityEngine.Networking.Match;
 using UnityEngine.Networking.Types;
 using System.Collections.Generic;
 
 public class NetWorkingServer : MonoBehaviour{
 
     public GameObject Menu;
     public Text hostList;
     public string gameName;
     public NetworkManager networkManager;
 
     //Usethisforinitialization
     void Start(){
         gameName = "game1";
         Menu.SetActive (false);
         networkManager = GetComponent<NetworkManager> ();
     }
 
     //Updateiscalledonceperframe
     void Update(){
 
 
 
     }
     void OnGUI()
     {
 
         //gameplay related
 
 
         //server related
             if(GUI.Button(new Rect(100,100,250,100),"StartServer")){
                 HostServer(gameName);
             }
             if(GUI.Button(new Rect(100,250,250,100),"Find Game/Hosts")){
             
             networkManager.matchMaker.ListMatches (0, 10, "game1", true, 0, 0, networkManager.OnMatchList);
 
             if (networkManager.matches.Count !=0) {
                 Debug.Log ("A list of matches was found");
                 foreach (MatchInfoSnapshot match in networkManager.matches) {
                     hostList.text = match.name.ToString () + System.Environment.NewLine;
                 }
             } else {
                 hostList.text = "No matches found";
                 Debug.Log ("No matches in requested room!");
             }
             }
 
         
     }
 
     public void HostServer(string matchName){
 
         networkManager.StartMatchMaker ();
         networkManager.matchMaker.CreateMatch (matchName, 4, true, "", "", "", 0, 0,networkManager.OnMatchCreate);
 
     }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by nasir_41 · Feb 02, 2017 at 06:19 AM

After Calling this Methode

networkManager.matchMaker.ListMatches (0, 10, "game1", true, 0, 0, networkManager.OnMatchList);

You probably need to wait for the callback here. And put the following code.. In the callback method.

if (networkManager.matches.Count !=0) { Debug.Log ("A list of matches was found"); foreach (MatchInfoSnapshot match in networkManager.matches) { hostList.text = match.name.ToString () + System.Environment.NewLine; } } else { hostList.text = "No matches found"; Debug.Log ("No matches in requested room!"); } }

Comment
Add comment · Share
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
avatar image
0

Answer by newbienoob · Feb 02, 2017 at 07:06 AM

@nasir_41 how would i go about waiting for the callback? i was under the assumption that NetworkManager.OnMatchList would automatically do that.

Comment
Add comment · Share
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

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

115 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

Related Questions

Unet local matchmaking 0 Answers

Unet- Null refernence OnMatchCreate , only on Iphone build 0 Answers

netcode throws hash errors when attempting to spawn local player 0 Answers

How to implement steam's matchmaking service with unity networking? 2 Answers

I'm getting an error: "AudioClip can't be deserialized because it has no default constructor" 1 Answer


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