- Home /
MasterServer with Unet ?
This is my NetworkManager. I'm using UI to trigger StartServer() function. Server has listening, Client can connect. But when OnStartServer() is trigger MasterServer say:
It's not possible to register a host until it is running.
public class NetworkManagerGUI : NetworkManager {
public override void OnStartServer(){
MasterServer.RegisterHost("PectsSurvival","Pects");
}
public void StartServer(){
ServerStarted= MyNetManager.StartServer ();
Debug.Log (MyNetManager.ToString ());
if (ServerStarted) {
Debug.Log("Started Server");
} else {
Debug.Log ("Error");
}
}
}
Answer by Leith_Ketchell · Feb 28, 2017 at 10:36 PM
I found that this error message is ambiguous, as you don't need to call StartServer in order for your host to be running!! The following steps worked for me... In order to register a hosted game with MasterServer, you must first call Network.Initialize( ), and then you can wait for the OnServerInitialized( ) event, and use that for a trigger to call the MasterServer.RegisterHost( ) method. You will then receive one of two possible events: OnMasterServerEvent( ) or OnFailedToConnectToMasterServer( ) , you can check the success or failure of RegisterHost by these two methods, and in the case of success, finally!, you can now call NetworkManager.StartServer( )