ReplacePlayerForConnection null reference

I’ve been tangling with Unet the last few weeks. I’ve created my own little lobby system fit for this game, which so far works pretty well. Now I’ve got an issue I can’t seem to fix on my own… the following code returns a null reference exception while I think it should work.

It spawns the prefab like it should and the entire command works pretty well except for the ReplacePlayerForConnection part. Anyone any ideas?

    [Command]
    void CmdSpawnPlayer(int slot, NetworkIdentity nIdentity)
    {
        NetworkManagerExtension manager = FindObjectOfType<NetworkManagerExtension>();
        GameObject player = (GameObject)Instantiate(manager.spawnPrefabs[slot], manager.spawnPrefabs[slot].transform.position, manager.spawnPrefabs[slot].transform.rotation);
        player.name = manager.spawnPrefabs[slot].name;

        NetworkServer.Spawn(player);
        NetworkServer.ReplacePlayerForConnection(nid.connectionToServer, player, nid.playerControllerId);
    }

Dont spawn the new player object before passing it to ReplacePlayerForConnection.

Dont pass a network identity in the command. the function is already called on your player object.

what is “nid”? pass base.connectionToClient as the connection to ReplacePlayerForConnection.