Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Player disconnects, all RPCs are deleted causing rigidbody error

Discussion in 'Multiplayer' started by HarrisonGPink, May 9, 2014.

  1. HarrisonGPink

    HarrisonGPink

    Joined:
    Apr 4, 2014
    Posts:
    45
    Hey guys, I've got a question about some interactions I'm not sure I fully understand.

    I've built a rudimentary pick up and throw system that works over the network. When a player picks up a cube, the server's cube tells all the client cubes to delete their rigidbodys as long as they are being held (to avoid weird clipping with the character controller). When the player throws the cube, it re-adds the rigidbody object. This works fine across the network as it's done with RPCs.

    However, if the 1st player that threw the cube disconnects, if a player (any player) then tries to connect to the server, the console spits a Missing Component Exception error, looking for a rigidbody that doesn't exist. At the time the 1st player disconnected, his version of the game reported that the cube had a rigidbody.

    So it seems to me that the "add a rigidbody" RPC that the 1st player sent has been deleted, but shouldn't that also mean that the "delete the rigidbody" RPC was also deleted? Why is the first part (delete rigidbody) being sent but not the second?

    Edit: This error only seems to happen in the Unity editor and only if the editor is one of the connecting players and not the server. If I open a series of built .exe's it seems to work fine.

    Any insight would be incredibly helpful. Thank you!
     
    Last edited: May 9, 2014
  2. HarrisonGPink

    HarrisonGPink

    Joined:
    Apr 4, 2014
    Posts:
    45
    bumping because I still don't know how to fix this editor only error. Help would be most appreciated!
     
  3. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    What happens if you disable the rigidbody instead of removing and adding it?
    Also, who removes and adds the rigidbodies? Who is the owner of the objects?
     
  4. HarrisonGPink

    HarrisonGPink

    Joined:
    Apr 4, 2014
    Posts:
    45
    I haven't found a successful way to simply disable a rigidbody without disabling the gameObject it's attached to. Is there a way to do this? That would solve a lot of my issues.
     
  5. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    Apparently there isn't, my bad.
    How do you remove the RPC's, maybe not all are removed.
     
  6. HarrisonGPink

    HarrisonGPink

    Joined:
    Apr 4, 2014
    Posts:
    45
    with this piece of code in my multiplayer manager:

    Code (csharp):
    1. void OnPlayerDisconnected(NetworkPlayer networkPlayer)
    2.     {
    3.         // When the player leaves the server, delete them across the network along with their RPCs
    4.         Network.RemoveRPCs(networkPlayer);
    5.        
    6.         Network.DestroyPlayerObjects(networkPlayer);
    7.     }
     
  7. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    hmm I see.
    If I recall correctly, Network.RemoveRPCs called on the networkplayer, doesn't remove all the RPC's.
    I think I ran into that one when I started to use the networking.
    What I usually do is store a reference to the gameobject or playerscript and then call the RemoveRPC on the viewid of the networkview of that player.
     
  8. HarrisonGPink

    HarrisonGPink

    Joined:
    Apr 4, 2014
    Posts:
    45
    Why does it only throw an error when the editor is a player but not if it's the server?
     
  9. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    Because the server never uses the buffered RPC's since it's online all the time. When the server disconnects, the buffer gets cleared.
    When a client connects, then it will get the buffered RPC's and throw an error.
     
  10. HarrisonGPink

    HarrisonGPink

    Joined:
    Apr 4, 2014
    Posts:
    45
    Aha, that makes sense.

    So why doesn't the connecting player get both the "delete rigidbody" and "add new rigidbody" RPCs? They're both buffered, it seems like both should be received, instead of only getting the delete rigidbody one.
     
  11. rsoares

    rsoares

    Joined:
    Mar 19, 2013
    Posts:
    35
  12. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    Check the network debug log and see if it gets the RPC's.