With Unity looking promising to me i wanted to try out prototyping a simple co-op implementation (no dedicated servers).
Looking at the older MultiplayerTutorial.pdf and the Networking example i wound up with this for the server-side:
if (GUI.Button(Rect(10,50,100,30),"Start Server")) {
connectionError = Network.InitializeServer(32, listenPort, useNAT);
for (var go : GameObject in FindObjectsOfType(GameObject)) {
go.SendMessage("OnNetworkLoadedLevel", SendMessageOptions.DontRequireReceiver);
}
}
Looks simple enough, but the server just freezes right away and with it the whole Unity Editor. I tried adding the callbacks for the various network failures and successes, but don’t see anything being logged after server initialization.
The screen just consists of a plane, a camera and a light. There is no relevant CPU load during the freeze.
Does anyone have some input on what could go wrong here?
InitializeServer is a blocking call, while it takes place nothing happens.
But I’m willing to bet that the problem is not the call itself, the problem is that you are totally bombing the engine with the ‘I inform everybody about the initialize’ instead of making the other components listen for the OnXXXX events from unity. Especially that you blindly search for GameObject instead of a specific monobehavior extend class is a total overkill, but that holds for find in general as it checks every single runtime object in the engine basically
Ok, for some reason this cleared itself after i just created a clean new scene and recreated what i had before. No idea why though.
Good point on that approach being overkill dreamora. I guess that tutorial used it as a simple way to do both the connection dialog and the actual level in one scene - definitely not something i’d want to keep later.