- Home /
UNET error when retrieving matches
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class CustomLobby : MonoBehaviour {
public NetworkManager manager;
public Text roomName;
public Dropdown lobby;
bool matchMaking;
//
public void MatchMaking(){
matchMaking = !matchMaking;
if (matchMaking) {
manager.StartMatchMaker ();
} else {
manager.StopMatchMaker ();
}
}
//
//
public void Refresh(){
lobby.options.Clear ();
for (int i = 0; i < manager.matches.Count; i++) {
lobby.options.Add (new Dropdown.OptionData () { text = manager.matches [i].name });
}
}
//
//
public void CreateMatch(){
manager.matchName = roomName.text;
manager.matchMaker.CreateMatch (manager.matchName, manager.matchSize, true, "", "", "", 0, 0, manager.OnMatchCreate);
}
public void JoinMatch(){
manager.matchMaker.JoinMatch(manager.matches[lobby.value].networkId, "", "", "", 0, 0, manager.OnMatchJoined);
}
//
}
This is my UNET script I'm trying to write for multiplayer. Creating works and Joining by finding the first lobby available works, but in my script I have a drop down menu I'm trying to use as a way to select the current lobbies made to join. But everytime I try to refresh the list using the Refresh function I made, I get this error
NullReferenceException: Object reference not set to an instance of an object
CustomLobby.Refresh () (at Assets/CustomLobby.cs:31)
I have no Idea why. I tried to see if it was just because no lobbies were made yet, but if I create a match on one window then refresh on a different game window, it still gives this error code. I'm super new to the UNET scripting and I've just been trying to make a new hud. Any help on this is greatly appreciated and if you have any tips please tell!
At least one of the reference type variables in line 31 is null. $$anonymous$$ake sure to check every variable, e.g. has manager been assigned?
Yes it is assigned which is why it's very strange to me. I've tried to replace manager.matches.Count with an actual number and it will get past that line then throw an error again when trying to add the options to the lobby variable. Create a match works fine so I know my manage is set up
Let me go ahead and say I followed an fps tutorial for unet that I ended up transferring the scripts to my current project. It honestly looks better now than what I was going to do.
Your answer
Follow this Question
Related Questions
Alternative to RPC for destroying objects across a network 0 Answers
Need help In creating android game with UI buttons ?Please Help 1 Answer
How to match UI Image size to UI Text size when using ContentSizeFitter on UI Text? 1 Answer
Editing UIElements Label through code and alignment 1 Answer
How can i scale a ui Panel from the left side only ? 2 Answers