How to manage interest groups

Options
Hello,
I am trying to make a videogame with minigames inside but I am having troubles with the interest groups of PUN. My interest is to instantiate a minigame only to the players who want to play it (and not to all the players of the current room). But I don't know if the instantiation needs to be done by one of these two players or needs to be done by the master client. But if the last one is the right one, how can we hide the gameobject instantiated to him? We realized that if a player instantiates a gameobject to the group 2 (for example), even though master client is not listening to the group 2, he can see the instantiated gameobject.
We use the following functions to subscribe the players to the new group:
PhotonNetwork.SetInterestGroups(byte group, bool enabled)
PhotonNetwork.SetSendingEnabled(byte group, bool enabled)


There's no much information and examples about this so I will be grateful if you can help me.
Thanks in advance,
Regards.

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited April 2021
    Options
    Hi @FranciscoJ,

    Thank you for choosing Photon!

    Instantiation and interest groups is a tricky combination.
    By design in PUN2 we decided to send the instantiation event in interest group 0 always no matter the PhotonView.Group or the group value you set in the instantiation call.
    One of the main reasons is that instantiation event needs to be cached and the server allows caching only for group 0.
    The other reason is that this led to issues and confusion in PUN Classic when people chose an interest group other than 0 and did not see the object instantiated locally because they did not subscribe to that group prior to receiving the instantiation event.

    Knowing this, in both PUN versions, on the client calling PhotonNetwork.Instantiate the object will be instantiated locally first no matter the interest group.
    The interest groups will be used for filtering incoming instantiate events.
    If the group is enabled/subscribed then the object will be instantiate if not the event will be skipped/ignored.
    RPCs will use the respective PhotonView.Group as a target interest group but if you use the RpcTarget.All, the RPC will be executed locally no matter the group. (Also in offline mode the same for AllViaServer but who wants InterestGroups in OfflineMode right?!)

    So I think you have two options:

    - always instantiate from a client who should see the object.
    - make use of custom manual instantiation to adjust according to your needs.
  • FranciscoJ
    Options
    Thank you very much @JohnTube, your answer has been perfect and now with this information I can make a more informed decision.
    Regards!!