question about OnSerializeNetworkView ...again...and again...;)

hi guys! i´ve a problem which is driving me crazy… i´m trying to rotate a torso which should be seen by all clients. the RPC version is pretty working but at high costs of kb/s (3,5k) while the the character´s amount of kb/s ist just 0.400… so i tryed to use OnSerializeNetworkView(…) but no data is send. can someone tell me what i´m doing wrong? :slight_smile:

using UnityEngine;
using System.Collections;

public class player_TorsoRotation : MonoBehaviour {
	public Transform torso;
	private float spin = 0;
	public float sensitivityX = 45f;
	public float smooth = 2f;
	Quaternion torsoRotationTemp;
	
	Quaternion temp;
	Vector3 tempVec = Vector3.zero;
	void Start(){
		if(networkView.isMine){
			torso.rotation = temp;
			temp = Quaternion.Euler(tempVec);
		}
		
	}
	
	void Update(){
		if(networkView.isMine) {
			if(Input.GetMouseButton(1)){ 	
				spin += Input.GetAxis("Mouse X") * sensitivityX;
				spin = Mathf.Clamp(spin, -sensitivityX, sensitivityX);
			}
			else if(!Input.GetMouseButton(1)){ 
				spin = 0f;
				//torso.rotation = temp;
			}		
			if(torso.rotation != temp  spin >= 0.5f || torso.rotation != temp  spin <= 0.5f){
				torsoRotationTemp = Quaternion.Slerp(torsoRotationTemp, Quaternion.Euler(0, spin,0), Time.deltaTime * smooth);
				torso.rotation = transform.rotation * torsoRotationTemp;
				//networkView.RPC("setTorsoRotation2", RPCMode.All, torso.rotation);
			}
		}
	}

	void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info) {
		// Always send transform (depending on reliability of the network view)
		if (stream.isWriting)
		{
			Quaternion rot = torso.rotation;
			stream.Serialize(ref rot);
		}

		else
		{
			Quaternion rot = Quaternion.identity;
			stream.Serialize(ref rot);
			torso.rotation  = rot;
		}
	}
	
	
	[RPC]
	void  setTorsoRotation2 ( Quaternion rota  ){
		//Debug.Log("setAnimationState called with index:"+aStateIndex);
		torso.rotation  = rota;
		//torso.rotation = transform.rotation * torso.rotation;
		//charMesh.animation.CrossFade(animations[aStateIndex], 0.2f);
		//Debug.Log(rota);
	}
}

Your networkview needs to ‘observe’ the script that contains the OnSerializeNetworkView function.

yeah, thx for the pointer!
…i thought it was okay when the network view observe the transform where the script is attached to. hmmm…obviously not. now the torso rotation seems to be “laggy”. ^^ anyway…i guess i´ll also find a solution to fix that.

interpolation/extrapolation