Please help - graceful cleanup of disconnected player

So I’m using OnPlayerDisconnected (NetworkPlayer player) along with Network.RemoveRPCs and Network.DestroyPlayerObjects.

However, what I’ve come to realize is that this is too disrupt-full to the game. Depending on what the character is doing when the connection drops, I need to perform other cleanup tasks to set the world back to a pristine state if the player left in the middle of doing something.

For example lets say I have a group of players tossing a ball around and one player is holding the ball when his network drops. Although I want to remove the player, I don’t want to remove the ball that was associated to him. In this case the ball isn’t even instantiated any more, but I know the player has it. If the player drops I want to instantiate the ball back to the scene for others to pick it up. This is not a persistent world so when the player logs back in he wont have the ball anymore. This is just one sample situation and in reality I can forsee all kinds of problems if I can’t gracefully clean up the player properly.

As it happens now the destroyplayerobjects gives me no control, and I don’t know how (if its even possible) to map the NetworkPlayer back to a GameObject so I can do some cleanup before calling DestroyPlayerObjects.

Anyone have any ideas. I really don’t want to re-architect my entire design for something that seems so trivial.

Thanks

Well I think I found a workaround. In the OnPlayerDisconnected I can loop through the players and match (networkView.owner == player). This seems to be working for me. I have some other quirky issues with the code but I’ll keep plugging away.

foreach(GameObject newGO in GameObject.FindGameObjectsWithTag(“PlayerRemote”))
{
if ( newGO.networkView.owner == player )
{
Debug.Log (“Found player”);
BallController newBC = (BallController)newGO.GetComponent(typeof(BallController));
if (newBC.pickedup)
{
BallSpawnManager newSpawn = (BallSpawnManager)GameObject.Find(“PickupSpawn”).GetComponent(typeof(BallSpawnManager));
NetworkViewID _nvid = Network.AllocateViewID();
newSpawn.networkView.RPC(“OnSpawnBall”, RPCMode.AllBuffered, _nvid, newBC.lastBallSpawn );

}
}
}

Why not detach the ball in OnDestroy?

In most games, you’ll lose the ball if your player is killed, and that append when you disconnect in that case…

atrakeur,

You’re absolutely right, but initially I didn’t know how to map a NetworkPlayer back to the player GO. Once I realize I could use (networkView.owner == player) the rest fell into place.

Originally I wasn’t actually carrying the object. Instead when I picked it up I destroyed it and set a flag, so detach wouldn’t apply, but when I throw it, I will need detach, othewise it’ll get wacked.

thanks for the reply.