OnSerializeNetworkView problem - Variables not serialized

Hello,

Please focus on the commented lines in the code.
The code below is used on the client and on the authoritative server.
It works - player send RPC, server moves the transform and sends data back to client (it should be optimized though).

I want to serialize player input instead of sending it via RPC, but when I put the data in the stream I get data only on the client end. Server is not receiving any!!

This part is not executed on the client:
print (“===========================”+F);

If you take a look at the commented code - it is not working - //Debug.Log (failF); - on server it is always 0.
I have tried many many variants, including disabling the RPC at all.

One other question - should I use FixedUpdate or Update - I have read the difference, but I am not sure which one is better.

using UnityEngine;
using System.Collections;

public class Movement : MonoBehaviour {
	
	private float speed = 5f;	
	private float turnspeed = 100f;
	private bool mine = false;
	private float vertical = 0f;
	private float horizontal = 0f;

	//private float failF = 0f;


	void FixedUpdate(){
		if(Network.isClient  mine == false){
			if(Connect.PlayerId==name) mine = true;
		}

		//Debug.Log (failF);

		if(Input.anyKey  mine == true){
			SendThisInput();

			
		}

	}


	void SendThisInput(){
		vertical = Input.GetAxis("Vertical");
		horizontal = Input.GetAxis("Horizontal");

		if((vertical!=0)||(horizontal!=0)) {
			networkView.RPC("handlePlayerInput",RPCMode.Server,Network.player,vertical, horizontal);
		}
	}
	
	void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
	{
		if (stream.isWriting)
		{
			Vector3 pos = transform.position;
			stream.Serialize(ref pos);

			Quaternion rot = transform.rotation;
			stream.Serialize(ref rot);
			
                        //float F = 123f;
                        //print ("==========================="+F);
			//stream.Serialize(ref F);
		}
		else
		{
			Vector3 rpos = Vector3.zero;
			stream.Serialize(ref rpos);
			transform.position = rpos;
		
			Quaternion rrot = Quaternion.identity;
			stream.Serialize(ref rrot);
			transform.rotation = rrot;

			//float receivedF = 0f;
			//stream.Serialize(ref receivedF);
			//failF = receivedF;
		}
	}
	
	
	

	[RPC]
	void handlePlayerInput(NetworkPlayer player, float vertical, float horizontal) {
		if(Network.isServer){
			transform.Translate(Vector3.forward * vertical * speed * Time.deltaTime);
			transform.Rotate(Vector3.up, horizontal*turnspeed*Time.deltaTime);
		}
	}
		
}

OnSerializeNetworkView sends from server to client or from owner of the networkView to others.
Not from client to server, you need to use RPC’s for that.
Client sends RPC with input data to server.
Server moves the client and updates all the clients through the OnSerializeNetworkView method.

Wrong - in the peer to peer setup I have serialized data to server and back and moved 2 transforms, each for a separate client only using OnSerializeNetworkView and no RPC. Like thiss

void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
{
    Vector3 syncPosition = Vector3.zero;
    if (stream.isWriting)
    {
        syncPosition = rigidbody.position;
        stream.Serialize(ref syncPosition);
    }
    else
    {
        stream.Serialize(ref syncPosition);
        rigidbody.position = syncPosition;
    }
}

Who is the owner of the object ?
When you debug the value received on the remote end, is it the correct value ?

I am not sure what are you asking - maybe I need some explanation regarding “owners” - not sure if I understand it. Is it the NetworkView which creates the object?
Objects are created with RPC from server to clients and assigned the correct viewIDs - for this I am sure.
if I turn on these rows:
float F = 123f;
stream.Serialize(ref F);

In my understanding this means:
Client - write 123 to stream and send it
Server - write 123 to stream and send it

So both sides - client and server - should receive 123, but when reading the stream only the client receives 123. Server gets 0;
As you see variables are in the correct order and count.
The settings on the NetworkViews on both sides are the default. The observer field points to the script (it will not work otherwise at all).

Some posts say that the owner is whoever runs Network.AllocateViewID - is this correct?
Then in my case it is the server, because it runs this method and send the view ID with the RPC to clients - then clients instantiate prefabs (with attached Network View) and assign them the ID server had sent.
Is it really that dumb - OnSerializeNetworkView sends only in one direction, depending who obtained the View ID?

Anyone?

I believe it is yes.
The owner is normally the one who instantiates the object. I’m not sure what happens when you assign an id.