Search Unity

Correct way to Network.Destroy(gameObject) ??

Discussion in 'Multiplayer' started by Griffo, Oct 29, 2013.

  1. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    I Network.Instantiate a RPG with -

    Code (csharp):
    1. var projectile = Network.Instantiate(RPG, transform.position, transform.rotation, 0);
    Then within the script attached to the RPG I have code to destroy the gameObject 2 seconds after it has hit the ground with -

    Code (csharp):
    1. networkView.RPC("killRPG", RPCMode.AllBuffered);
    2.  
    3. @RPC
    4. function killRPG(){
    5.  
    6.     Destroy(gameObject);
    7. }
    But the problem is sometime I get the error - View ID AllocatedID: 156 not found during lookup. Strange behaviour may occur I presume that a package gets through to the server before the gameObject is destroyed, is there a better way of destroying the gameObject over the network ?

    I've also tried -

    Code (csharp):
    1. Network.Destroy(gameObject);
    With the same results.
     
  2. Honikou

    Honikou

    Joined:
    Feb 18, 2013
    Posts:
    92
    when you instantiate, you add for example on group 1.

    Code (csharp):
    1.  
    2.  Network.Instantiate(fireball_prefab, weapon.position, rot, 1);
    3.  
    You can destroy the gameobject on each current player and futur player.

    Code (csharp):
    1.  
    2. private void destroy_me()
    3.     {
    4.         if (networkView.isMine)
    5.         {
    6.             Network.RemoveRPCsInGroup(1);
    7.             Network.Destroy(gameObject);
    8.         }
    9.     }
    10.  
     
    Last edited: Nov 5, 2013
    CarterG81 likes this.
  3. Griffo

    Griffo

    Joined:
    Jul 5, 2011
    Posts:
    700
    Thank you for the input, much appreciated ..
     
  4. Nims

    Nims

    Joined:
    Nov 11, 2013
    Posts:
    86
    I am very interested to know if this actually worked for you Griffo.
    As I am having very similar problems:
    I have a player gameObject which is Netwrok instantiated by the client. This player gameObject transmits data via RPC's to the server).
    When i destroy this object on the server, the player gameObject is still transmitting data to the server, until the command is reached to the client's game instance to destroy this object.
    The problem is that during this time a situation arises where the player gameObject is transmitting data while on the server it's already destroyed, giving rise to "Couldn't invoke RPC error" on the server itself.

    I have seen a similar posts with no real answers to this issue:
    http://answers.unity3d.com/questions/446083/couldnt-invoke-rpc-to-server-after-networkdestroy.html

    Any solutions to this?
    How would you go about destroying an object on the server side while it is transmitting data to the server from the client?
     
  5. Spokoda

    Spokoda

    Joined:
    Feb 7, 2013
    Posts:
    2
    The machine that spawned/ownes the object (usually the server) needs to perform the delete to keep it from updating other machines that would have already deleted their local copy otherwise. This could be done without significant changes to existing code by clients sending a 'DestroyRequest' message to the server and having the server call Network.Destroy rather than calling it directly on the client.