Search Unity

Lobby , join after server start

Discussion in 'Multiplayer' started by dreammakersgroupAdmin, Jul 3, 2012.

  1. dreammakersgroupAdmin

    dreammakersgroupAdmin

    Joined:
    Feb 13, 2012
    Posts:
    40
    i have problem.
    i did lobby system, which enable player to connect and see each other, when server start the game , server send "start" RPC to all client ( it is buffered).

    now if another client join after that he receive "start" call, in this function i do waiting till new client see all players and do some customization, when he click ready button i continue "start" which load the level

    but as soon as client connect the server he receive message from loaded level in server( i solved this by adding "Network.isMessageQueueRunning=false;" in the beginning of "start" function

    the problem is this solution prevent me to get others players name to show it in lobby window.

    any idea?
     
  2. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    I think the only way to do this is to always let your clients load whatever level the server is on as soon as the RPC comes in. If you want to hide this from the player then you can do that by disabling your main camera and rendering something else instead, but under the hood your clients must disable the message queue as soon as your load-level RPC arrives, and only reenable it when the scene is loaded - otherwise you'll get missed buffered RPCs, which is bad.
     
  3. dreammakersgroupAdmin

    dreammakersgroupAdmin

    Joined:
    Feb 13, 2012
    Posts:
    40
    is there other way?
    because main menu has a lot of textures and models it takes 250 mb in memory, i will try to reduce it as much as i can.
    but i don't think loading another scene beside main menu will be ok on mobile.

    if i keep only lobby screen loaded i will have another problem
    if new client join it will take long time to load the level then if client cancel it will take long time to go back to main menu
     
  4. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    I don't think there's really another way, with Unity's networking - unless you just forget buffered RPCs (and related things like Network.Instantiate) and manage the buffering yourself. This is not a crazy amount of work, but it's not trivial to get it right either.

    I would also ask, though, what are you making - a game or a menu? I've often been frustrated working on AAA console titles that we put up with long load times purely for the sake of adhering to a particular front end design. I'd gladly sacrifice visual fidelity in the menu in exchange for shorter load times (e.g. being able to preload the level, and being able to just pop up the menu on top of the game render when the level ends rather than endure a loading screen).
     
  5. Bluntweapon

    Bluntweapon

    Joined:
    Feb 24, 2012
    Posts:
    158
    You could do some complicated piece of juggling and having everything non-lobby related broadcast in a different network group, and whenever a player connects just disable sending messages in that group until that player finishes with the lobby and loads the next scene. The related methods are:

    http://docs.unity3d.com/Documentation/ScriptReference/Network.SetSendingEnabled.html
    http://docs.unity3d.com/Documentation/ScriptReference/NetworkView-group.html

    gfoot's right though, this won't help you with Network.Instantiate calls if there's any floating around, or heck, if it's called while you have that group turned off. Better off just Instantiate locally and use Network.AllocateViewID.

    Also there's no point of you having a buffered RPC here that just calls "Start" on your clients. You're better off just implementing a OnPlayerConnected and send off RPCs manually.
     
    Last edited: Jul 4, 2012
  6. dreammakersgroupAdmin

    dreammakersgroupAdmin

    Joined:
    Feb 13, 2012
    Posts:
    40
    if i disable sending how server send start , client should not start game until server do.
    another issue , if client still in lobby scene he will receive RPC from client in game scene. this mean i should disable receiving also
     
  7. Bluntweapon

    Bluntweapon

    Joined:
    Feb 24, 2012
    Posts:
    158
    You're not disabling sending altogether, just on one "channel", so to speak.

    i.e. have everything to do with the Lobby on GameObject1, and set its NetworkView to group 0. Everything that only has relevance in other scenes on GameObject2, and set its NetworkView to group 1.

    When a player connects, instead of a buffered RPC, manually send it in the function OnPlayerConnected (which should be on a script in GameObject1). In the same function, disable group 1 for that NetworkPlayer. Only when the client has confirmed it has finished loading the next scene do you enable group 1 again for that NetworkPlayer.

    As far as I know when another client sends off RPCs, it gets rerouted through the server anyway, so it shouldn't reach any players with that network group disabled.

    You can't actually disable receiving messages, I don't think.