OnPlayerDisconnected never called (I searched google and answers.unity3d.com)

Many people just write you add an OnPlayerDisconnected function. In docs it says to just add it to a monobehavior. Yet no-one specifies where you add this function. I tried overriding NetworkManager but no go.

So where exactly do I place this function to make sure it’s called on the server? If players call disconnect they are removed from server ok. If the just close the app they hang around until NetworkIdentity starts throwing errors.

Here are the docs:

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void OnPlayerDisconnected(NetworkPlayer player) {
        Debug.Log("Clean up after player " + player);
        Network.RemoveRPCs(player);
        Network.DestroyPlayerObjects(player);
    }
}

Hi,

You should use OnClientDisconnect, if you are using the new system called UNET or Unity NetWorking.
Network.OnPlayerDisconnected is from the old system.

OnClientDisconnect is a callback on the NetworkManager that is called on clients when disconnected from a server.

https://docs.unity3d.com/ScriptReference/Networking.NetworkManager.OnClientDisconnect.html