- Home /
State Synchronization question regarding OnSerializeNetworkView
I have one specific question regarding OnSerializeNetworkView.
if this is my function (Pseudo-code), then how do I deserialize the data if it might not be there?
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
if (stream.isWriting && Network.isServer)
{
if (positionChanged())
{
stream.Serialize(ref transform.position.x);
stream.Serialize(ref transform.position.z);
}
}
else if(stream.isReading && Network.isClient)
{
//HOW DO I TEST FOR POSITION CHANGED HERE?
}
}
More specifically, if the data never gets sent from the server because it hasnt changed, then how do I test for differences in the clients?
Thank you for you help.
EDIT: Changed the question and narrowed the focus
Answer by Gamingdrake · Jul 27, 2013 at 04:24 AM
For anyone that finds this, I figured out my problem right after I edited the post. The solution is to send a series of bits/bools as to what changed in your script. When the stream reads the data, read that sequence first to figure out what you have to read, and then parse the stream.
Answer by zachanima · Aug 20, 2013 at 08:22 PM
You may also want to look into the maxDelta
parameter of BitStream.Serialize.