The question is answered, right answer was accepted
Issuing SetClientReady causes duplicate network objects on local client
I am writing a client server game with UNet. I have created a working framework originally using NetworkManager class as a basis. I am now attempting to rework it without using NetworkManager.
At this point I have it mostly working, in that clients can connect to the host and pass messages back and forth reliably.
However, the local client is able to see the Hosts objects in the game scene. These objects are all spawned via NetworkServer.Spawn calls. This really becomes a problem when I issue a NetworkServer.SetClientReady message for the local client as it causes the local client to then spawn a local set of object instances. These obviously interfere with the ones on the host leading to some odd behaviour :)
Remote clients don't suffer this issue obviously and behave exactly as you would expect.
I am wondering if there is something I should be doing when spawning an object that is for the host, so that it doesn't appear on the local client's gamescreen?
Code snippet follows, this is all from my gameManager class. The hdl_ClientReady is called once my client sends a custom message to say that it is ready.
void Start() {
ClientScene.RegisterPrefab(tmpPlayerPrefab);
netConfig = new ConnectionConfig();
netConfig.AddChannel(QosType.Reliable);
}
void StartServer() {
NetworkServer.Configure(netConfig,10);
NetworkServer.Listen(7777);
}
private void hdl_ClientReady(NetworkMessage msg) {
NetworkServer.SetClientReady(msg.conn);
}
void OnClientConnect(NetworkConnection c ){
//....
NetworkServer.Spawn(n);
}
Answer by LinkoVitch · Sep 10, 2015 at 08:27 AM
This was caused by the local client connecting to the host via IP and not the internal local client connection. (This is done using ClientScene.ConnectLocalServer() )
Follow this Question
Related Questions
How should I verify that all of my client Object are created and ready after loading a new scene? 0 Answers
Adding Clients after Log in 1 Answer
NetworkServer.Send and NetworkClient.Send or synchronising on player prefab? 0 Answers
UNET - Both client and server player disappears for client after scene load 0 Answers
Synchronize scene loading networking 1 Answer