Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Network.Destroy when Player disconnects

Discussion in 'Multiplayer' started by nafonso, Feb 22, 2008.

  1. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    Hi,

    Whenever a player disconnects, I try to remove the objects that where owned by that player, with either Network.Destroy or Network.DestroyPlayerObjects and I get errors with the calling of the RPC, e.g.:
    I also get errors if I call RPCs with RPCMode.All. It seems that at least while on OnPlayerDisconnected, if I call an RPC it still tries to call on the player that exited. Isn't this a bug?

    Regards,
    Afonso
     
  2. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    277
    Yes, but it's only an error message being needlessly displayed. Besides that this is harmless but possibly annoying to see in the log. In short terms, this relates to keeping player references around after they've disconnected so they can be cleaned up (like with DestroyPlayerObjects), but then they also get included in broadcast messages which results in these error messages. Feel free to report a bug on this, I'll also note this down.
     
  3. nafonso

    nafonso

    Joined:
    Aug 10, 2006
    Posts:
    377
    Yes, seeing those messages annoys me! :wink: Already sent the bug report.
     
  4. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    What I'm currently doing to get rid of this (and gain more control, which I want and need to have for many reasons), is implementing an extra network layer in which I can control exactly whom I'm sending which messages.

    Obviously, I will lose some performance by using RPC(name, player,xx) in many loops, instead of RPC(name, RPCMode.Others, xx). For this, I think a new RPC signature (RPC(name, NetworkPlayer[] players, xx)) might be a cool thing to add to the Unity networking API (so that the loop could end up in some highly optimized C++ code created by our network-Masters ;-) - instead of creating a hell of P/invokes from the C#/.NET/Mono layer).

    On the other hand, I guess RPCs tend to be called sparse enough for this to not really be an issue after all (and when I want to do a "broadcast" to all the gazillions of players invading my servers, I can still use RPCMode.AllBUFFERED, so they'll never forget ;-) )...

    I might post the code of that "layer" when I feel it works stable and is designed well-enough for generic use (it'll probably remain just one single C#-class to which you can add and remove the relevant NetworkPlayers as you need it)... but don't count on that...

    Sunny regards,
    Jashan
     
  5. extragotcha

    extragotcha

    Joined:
    Mar 20, 2009
    Posts:
    42
    It looks like this bug is still there in 2.6.1

    Is there any simple workaround (apart from coding another networking layer like jashan) to prevent those error messages from coming up (thus blocking the Pause on Error feature) ?
     
  6. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Since Unity 2.1, you can use Network.SetSendingEnabled and NetworkView.SetScope instead of implementing your own network layer.

    Of course, you'll still need to do quite a bit of your own book-keeping. And it would certainly be nice to have the bug fixed (even though it's not too severe - but a cluttered logfile simply invites overlooking the stuff that really matters ;-) ).
     
  7. extragotcha

    extragotcha

    Joined:
    Mar 20, 2009
    Posts:
    42
    Indeed. Try{}catch{} isn't helping out either, unfortunately.
     
  8. Overflow_admin

    Overflow_admin

    Joined:
    Dec 30, 2012
    Posts:
    1
    I found a solution for the messy exception Couldn't send RPC function '__RPCNetworkDestroy' --> NOT A BUG!

    In the Spawner.js tutorial file, you might want to check what objects exist at what time, especially when they are being destroyed when the server stops!

    In the Networking.js tutorial file, when you shut down the server, you want to make your clients disconnect first (and that's not only for courtesy)
    function StopServer(){
    Debug.Log("Stopping server");
    networkView.RPC("RemoteDisconnect", RPCMode.Others); //Must make other players disconnect before server
    Network.RemoveRPCs(Network.player);
    Network.Disconnect();
    }

    function DisconnectFromServer(){
    Debug.Log("Disconnecting from " + serverIP + ":" + serverPort);
    Network.RemoveRPCs(Network.player);
    Network.Disconnect();
    }

    @RPC
    function RemoteDisconnect(){
    Debug.Log("Remote disconnect signal received");
    DisconnectFromServer();
    }

    Praise MonoDevelop-Unity /o/ /o/ /o/