OnSerializeNetworkView Sync problem

Here’s a demonstration video:

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);
		}

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.