PUN Lag Compensation

Hi guys!

I am little bit confused about PUN ability to compensate lags.

On one hand there is doc that explains how to

On the other hand, doc which compares Bolt and PUN says that PUN does not have lag compensation



  • up

    Anyone from Photon team ?
  • Hi @trixdyne,

    Thank you for choosing Photon!

    PUN does not have lag compensation built but you can do it yourself using what's available.
    The documentation gives you some pointers and hints on how to do so.

    Photon Bolt, however, have some of the techniques built-in.
  • edited December 2020
    It depends on how you are trying to compensate for the lag.
    If you are trying to account for a Position, Rotation or MovementSpeed of an object then you'll want to use Object Synchronization through a stream send and receive. This will send whatever variables you want to keep sync'd between all players 10 times every update (kind of like unity with fixed update where you calculate movements / logic then update its animations in Update()).
    Photon gives you some simple ones that you can use as documentation to create your own within your scripts.
    Just check out Photon Transform View & Photon RigidBody View scripts to see how they make use of their
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)

    Also as a tip, If you do choose to use the default scripts (Photon Transform View) rather than make a custom OnPhotonSerializeView:
    In your object movement script make sure:
    - all rotations / translates should be done in FixedUpdate not a coroutine as this causes the stream to go out of sync.
    - animations are updated in Update where a bool of its state is sent, avoid the use of triggers when you can.
    - If you do need to use a trigger, it may be better to use an RPC rather then have it in object synchronization.

    Also, to lessen the lag (at a cost to performance so use it wisely):
    - On whatever is lagging (player, enemy) select the PhotonView component attached, and change it from "Unreliable On Change" to "Unreliable", this makes it so it doesn't stop checking the stream when there hasn't been a change in stream.
    - Also, if you have a Photon Animator View component, on any animation that there is movement involved with, change "Discrete" to "Continuous". Discrete still sends data through stream 10 times an update, but when its in continuous, the values recorded since the last call are sent together. The receiving client then applies the values in sequence to retain smooth transitions.
Sign In or Register to comment.