- Home /
Networking questions
I have some questions about networking, so I decided to ask them here, because it seems like the only place where it is possible to get a quick answer.
So, first one: I heard that when hosting a server - host connects to himself like a client, but for some reason following code won't work
public override void OnClientConnect(NetworkConnection conn)
{
base.OnClientConnect(conn);
Debug.Log("Connect");
conn.RegisterHandler(MsgType.Connect, OnDoMagic);
}
It is an extension of NetworkManager. "Connect" is being written, but handler won't work. But when someone else, not a host connects - "connect" is also being written, but now handler would do his work. Why is this happening? What is wrong?
Second question: Spawning player. It's hard to say that unity official networking system is perfect. In fact, it spawns a player instantly when you connect to some server, and when I decided to make it a little more better - I got problems again.
NetworkServer.ReplacePlayerForConnection(conn, thePlayer, controllerID);
What is being stated for controllerID? I can't figure out. I have my "conn" NetworkConnection in my OnServerConnect override, but how do I get an ID of this connection?
Doing conn.playerControllers[0].playerControllerId
won't do a thing, obviously.
If someone could help me - I'll be gratefull. Thanks.