Search Unity

Network.Destroy does not work

Discussion in 'Multiplayer' started by Irix, Apr 2, 2009.

  1. Irix

    Irix

    Joined:
    Aug 6, 2008
    Posts:
    28
    Hi there,

    Is anyone else having bad luck with Network.Destroy? I can´t seem to make it work, both the gameObject and the network view ID ones. The object I´m trying to destroy is inside the scope, has a valid object and/or network view assigned and I get no errors on the console. It´s like the command is simply being ignored.

    Is there some weird behavior from Unity in this regard I´m not aware of? Any and all help is appreciated, I´m really stuck on this one.


    Btw, Network.Instantiate works just fine.

    Thx
     
  2. cyb3rmaniak

    cyb3rmaniak

    Joined:
    Dec 10, 2007
    Posts:
    162
    Worked like a charm the last time I used it...

    Was the game object you're trying to destroy instantiated? Or is it originally in the scene?

    Can you post some code of what you're doing?

    Edit:
    Try a quick search of the forum... There are already posts on the subject. See if any of them help you.
    Especially this one: http://forum.unity3d.com/viewtopic.php?t=15339&highlight=network+destroy
     
  3. Irix

    Irix

    Joined:
    Aug 6, 2008
    Posts:
    28
    Nothing fancy, really. Just calling


    Code (csharp):
    1.  
    2.  
    3. Network.Destroy(gameObject);
    4.  
    5.  
    or

    Code (csharp):
    1.  
    2.  
    3. Network.Destroy(networkView.viewID);
    4.  
    5.  
    on a collision callback.

    Is it a problem if the object has more than one network view, each tracking changes on different scripts?

    Ah yes, the object in question was instantiated. But it´s supposed to work the same way for objects that start in the level, I guess?


    Thx in advance,


    Sebastiao
     
  4. Irix

    Irix

    Joined:
    Aug 6, 2008
    Posts:
    28
    The specific message error I get is:

    even though I can confirm the object in question has an enabled networkView.

    Again, any help will be appreciated.


    Sebastiao
     
  5. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    280
    No, that should not be a problem.

    Yes, Network.Destroy should work as long as the object has a valid network view attached.

    OK, thats strange. As long as the object has a network view attached, calling Network.Destroy on the network views view ID or the game object of the network view should work. The error message indicates the it was given an invalid view ID number or a game object which does not have a network view attached.

    Have you tried enabling full network debug level in Edit->Project Settings->Network to get some hints on whats going on? You've probably already done this but how about printing some details on the object you are killing right before doing so, like getting the network views view ID and printing, the object name and verifying its the right object, etc?
     
  6. Irix

    Irix

    Joined:
    Aug 6, 2008
    Posts:
    28
    Yay! Found where the problem is. But for clarity´s sake, here is the code and the log info:

    Code (csharp):
    1.  
    2. bottomSegment.transform.position = topSegment.transform.TransformPoint(0, -0.5, 0);
    3. bottomSegment.transform.parent = topSegment.transform.parent;      
    4.  
    5. topSegment.active = false;
    6.  
    7. print(topSegment.name);
    8. print(topSegment.networkView.viewID);
    9.  
    10. Network.Destroy(topSegment.networkView.viewID);    
    11.  
    12. bottomSegment.GetComponent(ConfigurableJoint).connectedBody = rigidbody;           
    13. bottomSegment.rigidbody.isKinematic = true;
    14. bottomSegment.rigidbody.freezeRotation = true;
    15.  
    16. Destroy(bottomSegment.GetComponent(CapsuleCollider));
    17. topSegment = bottomSegment;
    18. topSegment.GetComponent(SynchObject).enabled = true;
    19. height = 0;
    20. segmentCount--;    
    21.  
    Both topSegment and bottomSegment are network instantiated objects. Now for the log:


    The root of all evil is here:
    Code (csharp):
    1.  
    2. topSegment.active = false;
    3.  
    I didn´t think that Network.Destroy would mind the object being inactive, but looks like it does. Anyway, it´s working now, thanks a lot for the help!


    Sebastiao