Search Unity

Staying connected between scene changes

Discussion in 'Multiplayer' started by Crey, Nov 27, 2009.

  1. Crey

    Crey

    Joined:
    Nov 24, 2009
    Posts:
    16
    When I create a server, players can connect to it, but if the server loads a new level, players cannot connect to it. Like the server disconnects when loading a new level.

    How can I get the server to remain intact when loading new scenes?
     
  2. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    You could use the 2.6 feature background loading, even though background loading seems to be bugged for me.
     
  3. Crey

    Crey

    Joined:
    Nov 24, 2009
    Posts:
    16
    Is there no other way to maintain connections between scenes?

    If not, than I might just have to load the level and then set up connections afterwards.
     
  4. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,553
    Perhaps if you try to use Application.LoadLevelAdditive()
    Would that work?
     
  5. psx

    psx

    Joined:
    Aug 25, 2005
    Posts:
    80
    The problem is most likely that whatever game object is handling the connections is getting destroyed when you load the level. The solution is to call "DontDestroyOnLoad()" on that game object before loading the level.
     
  6. Crey

    Crey

    Joined:
    Nov 24, 2009
    Posts:
    16
    And that game object would be the script it is called from? That makes sense, thanks for the help, I'm going to try it when I get back to school
     
  7. psx

    psx

    Joined:
    Aug 25, 2005
    Posts:
    80
    It all depends on what you're doing. I usually have a 'game controller' object with a script attached that handles users connecting, disconnecting, etc. When the new level is loaded, that object ( and it's attached script(s) ) gets destroyed, unless somewhere in that script you call "DontDestroyOnLoad(this)".

    Also look at turning the network message queue on and off while you load levels:
    http://unity3d.com/support/documentation/ScriptReference/Network-isMessageQueueRunning.html

    and here:
    http://unity3d.com/support/documentation/Components/net-NetworkLevelLoad.html

    psx