You can imagine Photon's "Interest Groups" as subchannels for conversations in a room: Clients only get the messages of Interest Groups they subscribed to (and group 0). They can send any event to any group they want to.
This simple feature can be used for basic Interest Management or any way you see fit. See the example use cases below.
Clients do not need to explicitly create interest groups. Interest groups are created on demand; when an actor subscribes to a new group number, the server will create it.
Photon offers up to 256 interest groups. The group number 0 is reserved and meant for broadcast: All actors (clients) inside a room are subscribed to group 0 and cannot unsubscribe from it. The other 255 groups are available to the developer to use freely. Any event assigned to a group > 0 will only be transmitted to clients that are interested in that group and in the room when the server relays the event.
The list of subscribed groups can be updated at any time inside the room by adding or removing their numbers using:
- Priority is always to group addition: if the same group number is added to both arrays then the group will be added.
nullarray acts as "no group" and an empty array (
new byte) acts as "all groups".
LoadBalancingPeer.OpChangeGroups(new byte, groupsToAdd)will remove all groups except the ones in
LoadBalancingPeer.OpChangeGroups(groupsToRemove, new byte)will add all groups no matter what the value of
- Since the
ChangeGroupsoperation does not return a response or trigger an event, each client should cache his interest groups locally if needed.
Example Use Cases
Interest Groups are useful to lower the number of messages per second inside rooms. By lowering traffic, you stay below the message/second limit, cut costs and sometimes it can help you increase the number of maximum players per room.
But you can come up with other clever ways of using Interest Groups in your game.
Most common use case of Interest Groups is Network Culling. Interest Groups could be mapped to areas of interest in your game. For instance if you have a "big fat world" you can separate it into smaller chunks, let's call them regions, and assign a group per region.
If you have teams in your game and want to implement team exclusive events, you can assign an interest group per team. All team members should subscribe to the team's interest group. Inter team events should be sent using the team's own group number. Intra team events should be sent using an opponent team's group number.