Search Unity

M2H networking tutorial question - best way to disconnect?

Discussion in 'Multiplayer' started by macfinch, Sep 22, 2010.

  1. macfinch

    macfinch

    Joined:
    Aug 24, 2010
    Posts:
    139
    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 :)
    -M
     
  2. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    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.
     
  3. AkilaeTribe

    AkilaeTribe

    Joined:
    Jul 4, 2010
    Posts:
    1,149
    Disconnect cleans the buffer.
    Changing level (LoadLevel) cleans the scene (therefore, the remaining objects).
     
  4. macfinch

    macfinch

    Joined:
    Aug 24, 2010
    Posts:
    139
    Hey appels, AkilaeTribe.

    Thanks for the replies, much appreciated :)

    -M
     
  5. impla007

    impla007

    Joined:
    Jan 30, 2010
    Posts:
    57
    I have the same kind of problem here..
    but changing level doesn't cleans objects with a
    Code (csharp):
    1. DontDestroyOnLoad (this);
    attached to a script.
    Is there a way to really clean the level and destroy all the remaining scripts ?
     
  6. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    DontDestroyOnLoad says what it does... it doesn't destroy.
    if you want stuff to be killed use destroy.
     
  7. AkilaeTribe

    AkilaeTribe

    Joined:
    Jul 4, 2010
    Posts:
    1,149
    Code (csharp):
    1. function OnLevelWasLoaded ()
    2. {
    3.     if (Network.peerType == NetworkPeerType.Disconnected)
    4.         Destroy (gameObject);
    5. }
    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.