Search Unity

Help Wanted (PhotonPUN) Where are all these messages coming from?!

Discussion in 'Multiplayer' started by AidanofVT, Mar 31, 2021.

  1. AidanofVT

    AidanofVT

    Joined:
    Nov 10, 2019
    Posts:
    104
    I'm making an RTS game, and I found that with just a few dozen units my messages per second was approaching the informal limit of 500. So, as one is supposed to, I removed the PhotonTransformViews from the units, and replaced them with a sytem that attempts to carry out similar simultanious simulations on all clients. This involves calling a position-correcting RPC about once per second per unit, and a navigation RPC about once every two seconds for per unit. So, compared to the default transmission rate of a PhotonTransformView, which I think is ten updates per second, this should be, at most, a fifth of the original messaging rate, right? Wrong. It looks like my messages per second is more than twice as high as when I was using PhotonTransformViews, although data-usage is reduced to a third of what it formerly was.

    What gives?! I did remember to make it so that my RPCs are only called when the object is actually moving, and I have been careful to run the same tests. Any insights would be appreciated.

    -Aidan
     
    Last edited: Mar 31, 2021
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,710
    The "secret" is that several PhotonView updates (via OnPhotonSerializeView) will be added to a single message, which makes the message count go down.
    You can do the same or similar for RPCs.
    Alternatively, if a PhotonView should not write each update, simply don't add data to the PhotonStream in OnPhotonSerializeView. This will skip the object's update but you don't need to time your RPCs yourself.
     
  3. AidanofVT

    AidanofVT

    Joined:
    Nov 10, 2019
    Posts:
    104
    @tobiass Thanks; I figured it was something like that. I've found that taking an even more hands-off approach, putting more faith in the simulation to work the same regardless of any floating-point shifts, has paid off. I've gotten rid of those position-update and navigation-update RPCs I mentioned, so my message rate is now under control.
     
    tobiass likes this.
  4. AidanofVT

    AidanofVT

    Joined:
    Nov 10, 2019
    Posts:
    104
unityunity