- Home /
OnSerializeNetworkView Sync problem
Here's a demonstration video: https://www.youtube.com/watch?v=Qf84jK-wjWo&feature=youtu.be
Look at front, the second player acts wierd.
Any suggestions?
I'm using the sandard OnSerializeNetworkView method for movement synchronization.
void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) {
if (stream.isWriting) //this is your information you will send over the network
{
sendPosition = this.transform.position;
sendRotation = this.transform.rotation;
stream.Serialize(ref isMoving);
stream.Serialize (ref sendPosition);
stream.Serialize (ref sendRotation);
}
else if(stream.isReading)//this is the information you will recieve over the network
{
stream.Serialize (ref realPosition);
stream.Serialize (ref realRotation);
}
}
And under update
if(!GetComponent<NetworkView>().isMine){
transform.position = Vector3.Lerp(this.transform.position, realPosition, 0.1f);
transform.rotation = Quaternion.Lerp(this.transform.rotation, realRotation, 0.1f);
}
Answer by Bunny83 · Jul 29, 2015 at 12:52 AM
The video link you've posted points to a private video, so we can't watch it. However i can see something which you're doing wrong. You always have to make sure that you read exact the same amount of data that you're writing. It looks like you're writing:
a bool value
a Vector3 value
a Quaternion value
but you only read:
a Vector3 value
a Quaternion value
That means the Vector3 actually overlaps with the bool value so everything afterwards get messed up. You have to read the same things in the same order that you write to the stream.
I'v tried it wtihout the boolean but the same thing occurs. I'v removed the video from private also. https://www.youtube.com/watch?v=Qf84j$$anonymous$$-wjWo
Your answer
![](https://koobas.hobune.stream/wayback/20220611233453im_/https://answers.unity.com/themes/thub/images/avi.jpg)