How to detect when player disconnects from master server?

Hello,

I am currently almost done with a Capstone project I have been working on for College. I had not had the need to ask any questions thats to this community and various tutorials; that is until now.

My game is a driving game that simulates how the roads/driving are/is in Puerto Rico. One part of this project is to create multiplayer, which we decided to use the Master Server provided by Unity.

I have the networkViews running and I can get players to join and interact the problem is I would like to detect for the Network.isServer side when a player has disconnected, so that i can reduce the number of players and Destroy that gameObject.

So my question is this, how do I detect from the server side, that a player has disconnected and destroy the object? I have 1 week left to finish and this would be a nice feature to have.

Thanks in advance, I really need your help if you can help me. I would not ask if I did not :frowning:

P.S. The Server side is another player A.K.A. the Host

There is a function called OnPlayerDisconnected which is called every time when a player disconnects from the server, maybe you are looking for that one. I used a code like this:

void OnPlayerDisconnected(NetworkPlayer networkPlayer)
	{
		// When the player disconnects remove them across the network, so nobody can see them
		Network.RemoveRPCs(networkPlayer);
		Network.DestroyPlayerObjects(networkPlayer);
	}