M2H networking tutorial question - best way to disconnect?

Hi all.

I’ve recently downloaded and gone through the M2H networking tutorial. I’ve started modifying ‘example 4’ to create a 3rd person shooter demo. All is going well though I’d like to know the best way to have the server and clients disconnect from the game and reload the ‘menu’ scene.

At the moment I’m just calling ‘Network.Disconnect’ from the scoreboard script and all clients disconnect just fine.

  1. I wanted to make sure if this is the way we would usually disconnect clients in Unity?
  2. Is there a cleaner way I should be doing this, such as removing any buffered network packets first, removing game objects etc? Or do all objects / packets simply get deleted when I load a different scene?

Thanks for help all :slight_smile:
-M

not sure about this but a client disconnection would mean all his buffered packets will get dropped.
There is a command Network.Destroy in the manual. you could call that on the server and destroy all.

Disconnect cleans the buffer.
Changing level (LoadLevel) cleans the scene (therefore, the remaining objects).

Hey appels, AkilaeTribe.

Thanks for the replies, much appreciated :slight_smile:

-M

I have the same kind of problem here…
but changing level doesn’t cleans objects with a

DontDestroyOnLoad (this);

attached to a script.
Is there a way to really clean the level and destroy all the remaining scripts ?

DontDestroyOnLoad says what it does… it doesn’t destroy.
if you want stuff to be killed use destroy.

function OnLevelWasLoaded ()
{
    if (Network.peerType == NetworkPeerType.Disconnected)
        Destroy (gameObject);
}

That should do it.

Edit : this is for the case when you have reloaded a level, and disconnected before, so it cleans the game object. For other purpose, you must specify the right if condition.