[UNET] Detecting when a player has connected

I’m trying to make it so that when a new player connects to the server, they’re added to a list. I know how to add things to a list, that’s trivial. What I don’t know how to do is get a new player connection with Unet. How do I do this exactly?

Easiest way is to have a script on the player object with a OnDisable method.

So there’s no really simple solution like an “OnClientConnect” or “OnClientDisconnect” that gets called on the host when they connect or disconnect for any reason?

OnDisable does that. It runs whenever the object is disabled due to disconnect. Works very reliably. If you are disabling the object during runtime yoursef this will cause an issue. Instead use OnDestroy then. But for all Network Callbacks, here they are:
https://docs.unity3d.com/ScriptReference/Networking.NetworkBehaviour.html

if you are do networking using unet NetworkManager you could override OnServerConnect, “if(connectiodId !=0) will ignore host itself”

protected int currentPlayers;

    public override void OnServerConnect(NetworkConnection conn)
    {
        if (conn.connectionId != 0)
        {
            currentPlayers += 1;
        } 
    }