UNET 5.2: How do you use NetworkServer.SpawnWithClientAuthority()?

I have a lot of questions that the docs never tells me. Here’s the link.


From the docs, this is the code that was given:

[Command]
void CmdSpawn()
{
    var go = (GameObject)Instantiate(
       otherPrefab, 
       transform.position + new Vector3(0,1,0), 
       Quaternion.identity);
       
    NetworkServer.SpawnWithClientAuthority(go, connectionToClient);
}

I know connectionToClient is from NetworkIdentity, but I don’t know which game object should I call on GetComponent<>() from, the owner of this NetworkBehaviour script, or the object that is being instantiated?


Another issue is NetworkIdentity.connectionToClient and NetworkIdentity.connectionToServer.

I know the usage for using connectionToClient in NetworkServer.SpawnWithClientAuthority() is because the caller is a Server. And connectionToServer in NetworkServer.SpawnWithClientAuthority() is because the caller is a Client. What I don’t get is, what if I want to spawn an object on the client, where the client has authority over the spawned object and not the server, and the client only controls that spawned object?

Is NetworkServer.SpawnWithClientAuthority() witht the usage of connectionToClient the correct usage for spawning a game object for the client to control only?


And finally, the last issue is the implementation of setting a prefab with child objects as a client-authority-only game object in a network game. Or a prefab with a list of objects that it wants to spawn into the game world after a mouse click action from the user.

Is using NetworkServer.SpawnWithClientAuthority() the correct method for use in such scenario?


Thanks in advance.

Welcome to the awfulness that is UNET documentation. It’s unbelievable how lazy the explanations are.