Prevent the connection player object to be destroyed when the corresponding client disconnects

So I override the NetworkManager.OnServerAddPlayer method, searches for an unassociated server pre-created player objects (controlled by AI) from a pool, and call NetworkServer.AddPlayerForConnection to associate this player object to the connection.

However, when the client disconnects, I wanted the previously associated player object not to be destroyed per client disconnect, but just return this player object back to the server player object pool and have the server AI to control the object again.

I was trying to override NetworkManager.OnServerRemovePlayer, and tried to either set player.gameObject to null, or call NetworkServer.ReplacePlayerForConnection with a null game object with the same player controller ID, and both approaches seem to not prevent the player object to be destroyed from the server when the associated client is disconnected.

So, is there a good way to prevent the connection player object to be destroyed on the server at all?

It turns out that NetworkManager.OnServerRemovePlayer is actually never called, which is actually a bug!
The work around is to override NetworkManager.OnServerDisconnect, and return the connection player object to the pool inside there. (by setting conn.playerController gameObject and unetView to null)

This “works” but looks like it leaves a lot of other stuff not cleaned up that would get done in DestroyPlayersForConnection and the subsequent calls to NetworkServer.DestroyObject. Did you find a clean way to do this? I tried to download the UNET repo and debug through it to figure out why my player was being destroyed even if I did stuff like unspawn it, remove authority, replace it with another player (but couldn’t get the debugger to step into the source.)