Set interest groups in RPC.

Is there a way to set which interest groups receive an RPC?

For example in my game I have a sniper rifle, obviously I want the sniper rifle to shoot further than my shotgun. So while I fire my Sniper shot I would want to use different groups to be able to receive the sniper shot then I would use for my shotgun shot.

Maybe I'm going about this idea wrong and there is something better all together to solver this problem?


  • Hi @seanybaby2,

    Is there a way to set which interest groups receive an RPC?

    The RPC is sent to the group, the PhotonView is currently in. You can set this group locally by using = interestGroupCode;. To find out more about Interest Groups I would recommend you taking a look at the related documentation page. This one also contains a section about PhotonViews.
  • Okay I see thanks @Christian_Simon....

    Hmm I'm having trouble coming up with an idea of how to solve my problem with this though. I'm currently using Network Culling with interest groups for movement/most guns etc...

    But what if I have an event that I want more users then normal to receive? If I have everyone share the same interest group for that event then wont that negate all of the networking culling I have been doing?

    The only work around I can think of and I'm not sure that I like it is to have everyone subscribe to receive events from some group (x). Tell all of the clients not to send messages to that group. Then when performing a global or long range event tell that client that it is sending the message to that global / long range group to subscribe to send messages that group for the duration of the event and then unsubscribe from it afterwords. This seems a bit unorthodox as I will also be sending over a lot of unnecessary data to all of the other clients like movement and anything else that is meant to be short range.

  • Hmm after doing a bit of digging it looks like I should use RaiseEvents instead of RPCS for my messages. That way I can specify which interests groups receive my messages and not just the ones I am currently in.

    Does this sound like a good approach or am I missing something?

    Are there any serious drawback to RaiseEvents? From what I have been reading they seem superior to RPC's but are little more complicated to work with. Are the performance costs similar?
  • Please note, that a client is always subscribed to the default group 0. You can't unsubscribe from that one. So if you have 'global' events, you can still use this group to make sure that each client receives this message.

    The difference between a RPC call and the RaiseEvent function is, that a RPC requires a PhotonView component and RaiseEvent is independent from PhotonView components and be be used without them. Internally a RPC is basically the same as a RaiseEvent call: both are using OpRaiseEvent.
  • Okay thank you for the insight regarding RPCs vs RaiseEvent's @Christian_Simon.

    I think I am understanding it now. Basically I set the interest group or groups for the client that wants to send the messages to specific other groups. So if I'm nearby players in region 3. I set there interest groups to 3. All of the local RPCS fire to 3. I then switch the interest group to 0 if I want a global event for that client. So basically players can subscribe to listen multiple interest groups but can only raise-events or cast rpcs to the interest group they are in.
  • Hey @Christian_Simon I just wanted to follow up with you and make sure my understanding of it above is correct^ thanks!
  • Hi @seanybaby2,

    what you basically want to use is PhotonNetwork.SetInterestGroups as described on the Interest Groups documentation page. You will only apply those changes to your local client. When using this function you can enable or disable receiving events and message from certain groups. However you can not disable the global group 0.

    When using the 'group' property of the PhotonView component, you apply those modifications only to your local client, too. When the OnPhotonSerializeView function is called for example, the message will be sent to the group which is set in the 'group' property. Means that any client who is subscribed to this certain group (see above) will receive this message. The same applies for RPCs.

    As described the RaiseEvent function differs from the previously mentioned behaviour because it is independent from a PhotonView component.

    Hopefully this helps. If not or if you have further questions, please get back here.
  • Hey Christian! Okay I think I got it now. Thanks for all the help. If I'm having trouble down the line I'll get back to you.
  • hey @Christian_Simon I'm actually building the system now and I've run into some problems. It looks like the PhotonNetwork.SetInterestGroups isn't working the way I imagined. The biggest issue being that I want to deliver messages to groups other then the ones I'm subscribed too.

    Correct me if I'm wrong but what I would like to do is locally create separate PhotonView's from the main character and send and receive messages on other groups then the main photonview is subscribed to. Sort of like a network message sender for different layer.
  • Did you consider using PhotonNetwork.RaiseEvent for this? It's independent from PhotonView components and offers the possibility to send to certain groups.
  • Did you consider using PhotonNetwork.RaiseEvent for this? It's independent from PhotonView components and offers the possibility to send to certain groups.

    Ahh! This is exactly what I was looking for. Thanks!
Sign In or Register to comment.