I’ve been having a problem cleaning up objects instantiated by the server, and have narrowed it down to the following, which is run on the server:
if( GUILayout.Button("BLARG!") )
{
if(ps)
Network.Destroy(ps);
else
ps =
Network.Instantiate( Game.vehicle.Get(Game.config.startingVehicle),
new Vector3(0,5,0), Quaternion.identity, 0)
as GameObject;
}
This creates or destroys an object on the server every time the button is clicked. On the first connection, everything works perfectly. The object shows up and dissappears on the client and server as expected.
However, if you disconnect the client and reconnect, the client creates all the objects that were created and destroyed on the server.
If you create and destroy the object 10 times, and disconnect/reconnect the client, you immediately get 10 objects on the server and none on the client.
My server has the following code, which I wouldn’t think should be necessary, as the objects are being instantiated by the server…but I have it in there out of desperation.
void OnPlayerDisconnected(NetworkPlayer np)
{
Network.RemoveRPCs(np);
Network.DestroyPlayerObjects(np);
}
If I connect multiple clients after a series of instantiate/destroys, each client gets the phantom objects.
Anybody know why this is happening?