Search Unity

NetworkView Sandwich Bug

Discussion in 'Editor & General Support' started by Fran, Oct 15, 2009.

  1. Fran

    Fran

    Guest

    Joined:
    Jun 12, 2009
    Posts:
    23
    Hi all!, im working on a multiplayer game and i found a major issue concerning the NetworkViews with multiple clients.

    This problem happens on "sandwich"-clients: naming like this at the clients which are not the last connected client.
    When a "sandwich" client disconnects and connects again to the server, it won't receive any data from the newly created NetworkViews on the server.
    Also, the reconnected "sandwich" clients won't receive any data from the previous NetworkViews that were "recreated": which means destroying the NetworkView and creating it again with the same viewID to solve the "Received state update for view ID AllocatedID: # but no initial state has ever been sent. Ignoring message." issue. (see http://forum.unity3d.com/viewtopic.php?t=11405)
    Only when the clients that had connected after this "sandwich" client disconnects, and the server recreates its NetworkViews, it will start receiving the data from the NetworkViews.

    This issue happens with the "stateSynchronization" set to "ReliableDeltaCompressed".

    I'm attaching a small proyect where you can reproduce this issue.

    These are the steps to reproduce the bug:


    1. On computer "A", click "Start Server".





    2. On computer "B", click "Join Game".



    3. On computer "C", click "Join Game".

    4. On computer "A" you should see the log of the 2 new connected clients.



    5. On computer "A", press "Add" which will create a new instance of NetTestInstace: this is a component that synchronizes a text through a NetworkView.

    6. On computer "A", add "something" into the TextField that has appeared.



    7. Notice that the text was synchronized on computers "B" and "C".





    8. On computer "B", click "Disconnect".

    9. On computer "B", click "Join Game".

    10. On computer "A", change the "something" text to "still works".



    11. Notice that the text was synchronized on "B" and "C".





    12. On computer "A", click "Add", and on the new TextField enter this: "this wont work on B".



    13. Notice that on computer "B", the second text was not synchronized, but on computer "C", it was.





    14. On computer "A", click on thefirst "Recreate NV" button.

    15. On computer "A", change the first TextField from "still works" to "not anymore on B"



    16. Notice that "B", was not synchronized and "C" was.





    17. On computer "C", click "Disconnect".

    18. On computer "A", click both two "Recreate NV" buttons.

    19. Notice that "B" is now synchronized.



    I cant use Network.Instantiate() on my game because im getting the prefabs from AssetBundles downloaded from the web.

    I was not able to find any workaround yet to solve this problem.

    I will paste the code here in case someone wants to check it without downloading the project.

    Please help!

    PS: here's the link to download the test project
    http://www.megaupload.com/?d=C2E4XUH3

    Edit: we uploaded the project to http://sandwichbug.1free.ws/ so you can test it.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    sounds like quite some of the issues could be solved by sending rpcs from client to server and then have the server issue buffered rpcs to all clients as well as generally create the object on the right side to then "share it with the others"
     
  3. Fran

    Fran

    Guest

    Joined:
    Jun 12, 2009
    Posts:
    23
    We are updating many ingame values (ie: hitpoints, player names, score, position, hashes, etc) so having an RPC for each sounds like discarding the use of ReliableDeltaCompressed NetworkViews, which is not an option for us.

    Even thought that doesn't fix the issue of having newly created objects not working after a "sandwich"-client reconnected.

    Thanks for your help.
     
  4. claustopholt

    claustopholt

    Joined:
    Mar 17, 2009
    Posts:
    9
    I had the same problem, and ended up wading through the network output to see what happened. Scope seemed to be set wrong, even though nowhere in my code do I otherwise use NetworkView.SetScope()!

    So try this: When you spawn the object (probably within an RPC), add this:

    Code (csharp):
    1. if (Network.IsServer) gameObject.networkView.SetScope(networkPlayer, true);
    It seems that "sandwich" users are an undocumented feature? At least the above magically works for me.
     
  5. Agustin

    Agustin

    Joined:
    Oct 30, 2009
    Posts:
    8
    Doing the next piece of code on the server on every NetworkView (nv), solves the sandwich bug:

    Code (csharp):
    1.  
    2. foreach (NetworkPlayer np in Network.connections)
    3. {
    4.     nv.SetScope(np, true);
    5. }
    6.  
    This must be done for the existing NetworkViews and also on any future NetworkView created after a sandwiched client connects to the server.