alvyxaz / barebones-masterserver

Master Server framework for Unity
475 stars 106 forks source link

Start Master Server #32

Closed CortexM4 closed 7 years ago

CortexM4 commented 7 years ago

Hi all. I'm try to start a master server after click on my button.

Alternative: Create a new script that will find Master in the scene, and call the master.StartServer() whenever you want (click of a button and so on)

I'm using singleton Master.Instance.StartServer();

and receiving this error

NullReferenceException: Object reference not set to an instance of an object StartServerScript.OnStartServerClick () (at Assets/FromScratch/Scripts/StartServerScript.cs:8)

This's occur because _clientsSocket is NULL in public virtual void StartServer() in Master.cs

OK, I've seen that code _clientsSocket = Connections.CreateServerSocket(); not executed because in Awake method (Master.cs) condition

if (ShouldBeDestroyed())
{
        Destroy(gameObject);
         return;
}

always TRUE

It's occur in Editor and in executable file. Flag Auto Start In Editor I'm disabled. After comment

Destroy(gameObject); 
return;

It's work fine.

PS: Sorry for my English. :)

alvyxaz commented 7 years ago

Hey!

Thanks for catching and reporting this!

I'll make sure it's fixed in the next update ;)