Search Unity

Old destroyed objects re-instantiated on new clients??

Discussion in 'Multiplayer' started by jshmrsn, Feb 4, 2010.

  1. jshmrsn

    jshmrsn

    Joined:
    Jan 31, 2010
    Posts:
    8
    Hi,

    I am now having the problem of objects being instantiated on newly connected clients after they've been destroyed on the server.

    I understand this is because the RPCs are buffered and there's nothing getting rid of those buffered RPCs after the Network.Instantiated objects are destroyed.

    I don't see any way of fixing this, though... Could anyone give me some guidance with this? I'm stumped.

    If I run a round of my game and fire 500 bullets (which are all destroyed a second after creation) and then connect a new client later on, 500 bullets are spawned immediately on the new client and pretty much crash the game :(

    I would of course like to preserve the functionality of objects being automatically created on the client which were created on the server as this is very helpful. I just need a way to clear those RPCs after the corresponding objects have been destroyed.

    It doesn't seem like simply using RPCs groups will help - there can only be 32 of those, right?

    Thanks,
    Josh
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Sounds like you didn't clean the RPC buffers on leaving.
     
  3. jshmrsn

    jshmrsn

    Joined:
    Jan 31, 2010
    Posts:
    8
    I could be wrong, but I don't think that's the issue because the problem can be replicated without any clients leaving.

    Example:

    ServerA starts a game.

    ClientA connects.

    The ServerA player and ClientA player start shooting at each other. 500 bullets are created with Network.Instantiate. Of those, only 3 are currently still flying (the rest have been destroyed with Network.Destroy().

    ClientB connects. All 500 bullets are immediately created on ClientB's screen (instead of just the desired 3).
     
  4. jshmrsn

    jshmrsn

    Joined:
    Jan 31, 2010
    Posts:
    8
    Is there really no solution to this? I can't see how to go forward with Unity development with this problem :(

    The only solution I can think of is to create a unique RPC Group for every object that is Network.Instantiated and then calling Network.RemoveRPCsInGroup() for that unique RPC Group in that objects OnDisable()... if(networkView.isMine)

    However, this will not work because of the (undocumented?) limit of 32 RPC groups.

    My desired functionality is for Network.Destroy() to remove the buffered RPCs that were created with the corresponding Network.Instantiate()

    This seems very reasonable...

    Should I move this question up to Answers?
     
  5. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
  6. jshmrsn

    jshmrsn

    Joined:
    Jan 31, 2010
    Posts:
    8
    Thanks for the reply and confirmation Leepo. I actually read through that while I was reading your tutorial (which was of course extremely helpful :) ). Didn't see anything else about it in the forums or answers, though.

    Do you have any tips as to how I could do it myself? If there's only 32 RPC groups (also from your pdf), how else could I possibly pinpoint those buffered RPCs for removal?

    Have you heard anything from Unity? It would be great if they at least confirmed if this was bug or intended functionality.

    I posted in answers: http://answers.unity3d.com/question...rk-instantiate-not-removed-on-network-destroy

    By the way, I think I found a solution to your "Be able to distinguish an empty masterserver list from awaiting a masterserver response." issue. You can use OnMasterServerEvent to detect when the list response has been completed.

    Code (csharp):
    1.    
    2.         void OnMasterServerEvent(MasterServerEvent msEvent)
    3.     {
    4.         if(msEvent == MasterServerEvent.HostListReceived)
    5.         {
    6.             _isRefreshingList = false;     
    7.         }
    8.     }
    9.  

    - Josh