- Home /
Question by
timcommandeur · Aug 09, 2013 at 01:06 PM ·
networkingmultiplayernetworkcomponentnetworkview
Networking dupplicate processing of components
Hey all,
I'm currently implementing multiplayer in my game. I have a server game and a client game which are both identical except that one initializes the server and the other connects to it. I instantiate player objects on both processes, which have a bunch of components and a network view which only observes the position of the players.
My question now is: Do both processes add the components to the player objects, if so, do they both execute all the component methods? Or is the built in network functionality smart enough to only update the components on the objects that were instantiated on it's own process?
This is the code I use to initialize the game client or server:
private void init(bool isServer)
{
if (isServer)
{
Network.incomingPassword = "hoi";
bool useNat = !Network.HavePublicAddress();
Network.InitializeServer(32, 1234777, useNat);
// Player is a prefab with a collider, rigid body and a bunch of other stuff.
GameObject player = Resources.Load("Player") as GameObject;
GameObject instance = Network.Instantiate(player, new Vector3(0, 20, 0), Quaternion.identity, 0) as GameObject;
gameObject.GetComponent<PlayerController>().player = instance;
Camera.main.GetComponent<CameraLook>().target = instance;
}
else
{
Network.Connect("192.168.178.11", 1234777, "hoi");
}
}
// In case the current process is a client and has connected to the game.
void OnConnectedToServer()
{
GameObject player = Resources.Load("Player") as GameObject;
GameObject instance = Network.Instantiate(player, new Vector3(0, 20, 0), Quaternion.identity, 0) as GameObject;
gameObject.GetComponent<PlayerController>().player = instance;
Camera.main.GetComponent<CameraLook>().target = instance;
}
Comment