- Home /
Network syncing between Clients
Does OnSerializeNetworkView
only work between a client and a server? Does it work between 2 clients as well?
I have an architecture where the clients need to communicate with each other on a regular basis.. RPC is not an option, so I tried doing this using the OnSerializeNetworkView
, but for some reason, when the stream is reading, I do not get any values from the stream.
When I check the log on the server, it is getting values from both the clients. So is this actually how communication works using the OnSerializeNetworkView
syncing method?
Thanks!
OnSerializeNetworkView
routes the information through the server to everyone who has a game object with the same viewID
- all clients, and the server, without any filtering options.
Oh! I did not know that.. I had an if (client) condition in the OnSerializeNetworkView method, which was preventing this from happening. As a result I was getting 0 values when I was reading on the client. But removing that condition solved the problem! Thanks!!
$$anonymous$$y pleasure.
Remember also that the NetworkPlayer
who called either Network.Instantiate
or Network.AllocalteViewID
is the owner of that object as far as the network is concerned (the last player to call AllocateViewID
takes ownership of that object) and is the one where the stream.isWriting
will return true.