Search Unity

Destroyed objects show up on newly connected players

Discussion in 'Multiplayer' started by TJB, Mar 19, 2008.

  1. TJB

    TJB

    Joined:
    Mar 20, 2007
    Posts:
    146
    When I network destroy a object that was instantiated by the server any clients that connect to the server after the object is destroyed have a instance of the object in their scene.

    I was wondering if anyone might know what i'd need to do to prevent this from happening?

    Thnx for any help you can provide.
     
  2. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    Since I've had the same issue, I guess that Network.Instantiate uses buffered RPCs. I can see two solutions to this: One is using groups and removing the buffered RPCs (don't have the name of the method in my mind right now, but it's well documented). The other one is: Not using Network.Instantiate and doing the network instantiation yourself. There's a good example for how to do this I think in the docs in NetworkView.RPC(...)

    Sunny regards,
    Jashan
     
  3. TJB

    TJB

    Joined:
    Mar 20, 2007
    Posts:
    146
    Thanks for the advice, I feel myself getting close to solving it, but I'm still having problems. I made a simple scene to figure it out as follows:

    The first script is attached to the camera and allows the user to start a server or connect. If the player starts a server a prefab is network instantiated.

    this is attached to the instantiated object:
    Code (csharp):
    1. function Start () {
    2.     if (Network.isServer) {
    3.         networkView.group = 1;
    4.         Network.Destroy(gameObject);
    5.         Network.RemoveRPCsInGroup(1);
    6.     }
    7. }
    So if i start this up and launch the server, then open a second instance and connect the prefab is still around... If i change:
    Network.RemoveRPCsInGroup(1);
    to:
    Network.RemoveRPCs(Network.player);
    it works, but that doesn't help me.


    If what i wrote makes sense any help would be great.
     
  4. TJB

    TJB

    Joined:
    Mar 20, 2007
    Posts:
    146
    ok, figured it out... in:
    Network.Instantiate(testobject,transform.position,transform.rotation,0);
    the 0 at the end defines the group... was just blindly putting it in until now :D
    and what i have above defines the group of the networkview... not the instantiation