- Home /
How does BitStream work?
I've downloaded the official Networking example.
Both non-auth server and auth server example use state synchronization to update position. And both example use this code:
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
// Always send transform (depending on reliability of the network view)
if (stream.isWriting)
{
Vector3 pos = transform.position;
Quaternion rot = transform.rotation;
stream.Serialize(ref pos);
stream.Serialize(ref rot);
}
//................
}
It work properly but I got confused. In the case of non-auth server, the program keep sending transform to server when the object is own by local client. On the other hand, auth server use the same code but it seems only when it runs as a server does the transform send.
So my question is: how does BitStream determine whether it should send information or not?
Answer by Sprite101 · May 22, 2012 at 03:18 PM
It depends on who owns the NetworkView, which is generally determined by which Network allocated the NetworkViewID or which Network called Network.Instantiate.
The owner of the NetworkView generally writes to the BitStream, while all other networked clones read from the BitStream.
Now in the case of what you're trying to do here, you can just set the NetworkView to watch the Transform of the object, which will most likely be more optimized. You could create another network view to watch the script if there's any other data that needs to be updated frequently, but RPC calls are usually sufficient.