#ReplacePlayerForConnection is unspawned?

1 messages · Page 1 of 1 (latest)

magic lintel
#

Hello there! I'm trying to replace the player object for the connection of a client, but the connection seems to be null?
I tried following this forum post (https://forum.unity.com/threads/connectiontoclient-is-null.483886/), and this GitHub issue (https://github.com/MirrorNetworking/Mirror/issues/3105)
Making the replace function a command seemed to get me a bit further, but still don't have the desired behaviour. Here's my code:

[Command(requiresAuthority = false)]
    public void CmdReplacePlayer(GameObject newController)
    {
        NetworkManagerSchabby.singleton.ReplacePlayer(GetComponent<NetworkIdentity>().connectionToClient, newController);
    }
public void ReplacePlayer(NetworkConnectionToClient conn, GameObject newPrefab)
    {
        Debug.Log(conn);
        Debug.Log(conn.identity);
        Debug.Log(conn.identity.gameObject);

        GameObject oldPlayer = conn.identity.gameObject;
        NetworkServer.ReplacePlayerForConnection(conn, Instantiate(newPrefab), true);
        Destroy(oldPlayer, 0.1f);
    }

The error:

GitHub

Describe the bug connectionToClient is null unless it's a host. I tried over my localhost 2 clients, and the host client runs without problem, and the client client gives the object not set to ...

#

When I run it on host, the game continues on, but there's no player object. Running on client kicks me from the server.

#

Maybe it has something to do with running it without authority?