PhotonView sending updates despite no change

Options
Hi!
I have a GameObject with a PhotonView observing the script below. The PhotonView Observe Option is set to "Unreliable On Change". I've also tried "Reliable Delta Compressed". In both cases, the transform position and rotation are being spammed out from the master client to all other clients, despite not changing. Its a little bit magic to me how PhotonView's can tell which data is the data to trigger updates on, so maybe my lack of understanding there is the problem.

Thanks for any and all help. :)

-tim

Here is my amazing, totally-not-copied-from-the-viking-tutorial script:

public class NetworkCharacter : Photon.MonoBehaviour
{

	private Vector3 correctPlayerPos;
	private Quaternion correctPlayerRot;
	bool appliedInitialUpdate;

	void Awake()
	{
		appliedInitialUpdate = false;
	}

	void Update()
	{
		if (!photonView.isMine)
		{
			transform.position = Vector3.Lerp(transform.position, this.correctPlayerPos, Time.deltaTime * 5);
			transform.rotation = Quaternion.Lerp(transform.rotation, this.correctPlayerRot, Time.deltaTime * 5);
		}
	}

	public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
	{
		if (stream.isWriting)
		{
			GameController.instance.TimedLog ("NetworkCharacter sending message to client for GameObject " + gameObject.name + ", position " + transform.position + " and rotation " + transform.rotation);

			// We own this player: send the others our data
			stream.SendNext(transform.position);
			stream.SendNext(transform.rotation);
		}
		else
		{
			GameController.instance.TimedLog ("NetworkCharacter receiving message from server for GameObject " + gameObject.name + ", position " + transform.position + " and rotation " + transform.rotation);

			// Network player, receive data
			this.correctPlayerPos = (Vector3)stream.ReceiveNext();
			this.correctPlayerRot = (Quaternion)stream.ReceiveNext();

			if (!appliedInitialUpdate)
			{
				appliedInitialUpdate = true;
				transform.position = correctPlayerPos;
				transform.rotation = correctPlayerRot;
				UnitMovement movement = GetComponent<UnitMovement> ();
				Debug.Assert (movement);
				movement.TeleportToLocalPosition (correctPlayerPos);

			}
		}
	}
		
}

Comments

  • Tobias
    Options
    I looked at the "Demo Boxes" and used the "PhotonStatsGui" in the scene. The prefab for the boxes is set to "Unreliable On Change".
    When I create a few boxes, messages go out but once they stop moving, the messages stop, too.

    Maybe your objects don't really stop moving due to lerping?

    PUN keeps the last sent values of an object in-memory. Before an update gets sent, PUN compares the new values with the old and if skips sending them when they are "almost the same".
    Check PhotonNetwork.precisionForVectorSynchronization, .precisionForQuaternionSynchronization and .precisionForFloatSynchronization.
    You can also have a look into NetworkingPeer.AlmostEquals().
  • timflechtner
    Options
    Ty Tobias! I'll check those things now. Sorry to be so long in responding.