saving bandwidth using IPunObservable question

Options

lets say i only want to broadcast the data only if there is any changes, do i need to do it like this, or is photon already handled such thing and only transfer if there is changes? the idea is i dont want to transfer data every tick and only transfer if there is any changes.


  public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)

  {

    if (currentHealth != lastHealth && stream.IsWriting) // check if there is changes

    {

      stream.SendNext(currentHealth);

lastHealth = currentHealth; // set as the latest update

    }

    else

    {

      currentHealth = (int)stream.ReceiveNext();

    }

  }

Answers

  • Tobias
    Options

    It is better if you only send the changes. PUN 2 has "Reliable Delta Compressed" mode for PhotonViews but it doesn't support a lot of value types and sending the updates reliable is a requirement here (but can introduce lag due to loss).

    Alternatively, you could head over to Fusion, which is our upcoming solution for networking. It automatically compresses the data that didn't change and is so effective that you don't have to worry about this anymore.

  • so the idea is to limit sending (stream.writing). and you should be fetching every tick (stream.ReceiveNext()). right?