- Home /
NullReferenceException: Object reference not set to an instance of an object
Error: NullReferenceException: Object reference not set to an instance of an object MenuManager.Menu_LanServer () (at Assets/Scripts/MenuManager.cs:55) MenuManager.OnGUI () (at Assets/Scripts/MenuManager.cs:28)
Code Lines 51-61:
private void Menu_LanServer()
{
if(GUI.Button(new Rect(10,10,200,50), "Start Server"))
{
MultiplayerManager.instance.StartServer(MatchName, MatchPassword, MatchMaxPlayers);
}
if(GUI.Button(new Rect(10,65,200,50), "Back"))
{
NavigateTo("Main");
}
StartServer in MultiplayerManager:
public void StartServer(string servername, string serverpassword, int maxusers)
{
MatchName = servername;
MatchPassword = serverpassword;
MatchMaxPlayers = maxusers;
Network.InitializeServer(MatchMaxPlayers, 1192, false);
Network.InitializeSecurity();
MasterServer.RegisterHost("DeathMatch", MatchName, "");
}
Also "public static MultiplayerManager instance;" is declared and in the Start void i have declared "instance = this;"
Please help :(
Answer by Loius · Jan 18, 2013 at 12:40 AM
One of these should fix it:
Is there exactly one object in the scene with the MultiplayerManager component attached? (there should be)
Is there any way for Menu_LanServer to run before that object's Start function? (there shouldn't be)
$$anonymous$$enu_LanServer only runs when i click a button and how do you mean only one object in the scene with $$anonymous$$ultiplayer$$anonymous$$anager attached.. I had the exact same problem as i am having now with adding a box for the player to be able to write his/her name and that executed on start and would spam errors saying it wasn't set to an instance..
Oh by the one object, yes I have an empty game object with the script added and i'm still getting this error :/
Fixed my void Start in $$anonymous$$ultiplayer$$anonymous$$anager was a lower case s therefore was running... Rookie mistake, Thanks for your help :)
Your answer
Follow this Question
Related Questions
I am having a problem with the following script 1 Answer
Calling 'AddItem' Method giving me error NullReferenceException: 0 Answers
Why am I getting NullReferenceException on my .Contains()? 1 Answer
Null Reference exception help 2 Answers
Import Componet ( Variable ) Error Unexpected Token 3 Answers