- Home /
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.
On my tests connectionToClient and connectionToServer are always null. How did you even get anything useful on them?
Answer by sglindme · Mar 22, 2016 at 04:27 PM
Welcome to the awfulness that is UNET documentation. It's unbelievable how lazy the explanations are.
Your answer
Follow this Question
Related Questions
Commands and ClientRPC are not running when called 0 Answers
NetworkManager.ServerChangeScene from client to server 0 Answers
Different Network Behavior in adding player between editor play and built 0 Answers
Unet Client child object not rendering 0 Answers
ClientRpc Function not being carried out on all clients in Unity3d c# 0 Answers