I came up with my own Network Culling Approach

I read the culling demo on photon website. I personally don’t like the approach because if my character stands on one side of the area border and another player is standing on the other side of the border, I can see the other player’s actions being laggy.

I came up with a approach. I haven’t tested it. Feel free to point out any problems.

My approach is simple.
Every player has a unique number as his own channel(being 1-255).
Every player is subscribing to his own channel and the public channel (0).
Therefore, at start of the game, run this

PhotonNetwork.setInterestGroup(new byte[0], new byte[] {0,myChannel} );

If my character get closer to other player’s character, I will subscribe to his channel.
This can be achieved by a sphere collider attached to my character. At OnTriggerEnter(), I will set interest group to my channel, his channel, and public channel zero.
When I get farther away from him, I will unsubscribe from his channel. Again, this can be done at OnTriggerExit(), and set interest group back to my channel and public channel.
My character’s Photon View will send 19 message to my own channel. Then, send one message to public channel zero. This can be achieve a simple counter inside OnPhotonSerializeView().

As a result, if the other player is far away from me, I can only receive his position and rotation from the public channel every two seconds. His position and rotation will only update every two seconds. If he is close, he will subscribe to my channel, and I will subscribe to his, which we both receive each other’s update 10 times a second.





Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @waynemmmm,

    Thank you for choosing Photon!

    Your approach is fine.
    It's called interest group not channel as channel can mean other things in Photon.
    No need to subscribe from Interest Group 0, this is done by default and you can't unsubscribe from it.
  • Thanks @JohnTube,

    I will be careful with terminology to prevent confusion.

    I implemented my method in the game with a distance checked. It loop through all the other player’s transform and decide whether to subscribe or unsubscribe to his interests group.

    It works! When the others are far away, I can see their movement being laggy in the unity editor. When they are close, the movements become smooth. When the remote player needs to call an important RPC (such as switch weapon)that should not be missed by culling, I simple add “photonView.Group=0” before the RPC call. Then this RPC call will reach everyone despite the distance.

    The purpose of doing this is I want to minimize message/s to up scale my room size to 64 people.
    However, after implementing culling, I check my dashboard. There was a match last night involved 4 player which has a peak message/s of 200. The peak bandwidth usage was 10kb/s

    I want to know is it safe to up scale with the current culling method?
    4 people and 200 message, I think it is still a lot. I don’t know where I can still improve.

  • JohnTube
    JohnTube ✭✭✭✭✭
    Hi @waynemmmm,
    I simple add “photonView.Group=0” before the RPC call. Then this RPC call will reach everyone despite the distance.
    You could use RaiseEvent directly. Or if you send an RPC directly to a player using the overload method that accepts Player object then the target view group will be ignored (when sending an RPC or event to target actors, interest group is not used) unless you explicitly added it to a list of groups you block sending to locally via SetSendingEnabled(group, false). i'm saying this as changing the view's interest group may alter how you use the culling even if you revert back the group after the RPC call.
    I want to know is it safe to up scale with the current culling method?
    Does not hurt to try. You could try to group/aggregate messages/calls if possible. Do you use SetProperties?

    M2H reached 1000 msgs/s for 32 players, you can use this as a reference (500 msg/s limit is soft in case you are asking)