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?

Comments

  • 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 photonView.group = 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.
Sign In or Register to comment.