[PUN2] Interest group not work

Hello,
I am a new user of Photon Voice 2. I tried to create voice groups between players, then in order to test I built 3 versions of the game adding the following code in the Start method of a new script attached to the players where the use case is:
Players with interest group 1 can listen between them
Players with interest group 2 can listen between them
Everybody can listen to players with interest group 0
Players with interest group 1 cannot listen to players with interest group 2 and vice versa

The first version have this code:
Player 1:
#Unsuscribe from 1
PhotonNetwork.SetInterestGroups(new byte[0] { 1 }, null);
#Unsuscribe from 2
PhotonNetwork.SetInterestGroups(new byte[0] { 2 }, null);

#Suscribe to 1
PhotonNetwork.SetInterestGroups(null, new byte[0] { 1 });
The second version have this code:
Player 2:
#Unsuscribe from 1
PhotonNetwork.SetInterestGroups(new byte[0] { 1 }, null);
#Unsuscribe from 2
PhotonNetwork.SetInterestGroups(new byte[0] { 2 }, null);

#Suscribe to 2
PhotonNetwork.SetInterestGroups(null, new byte[0] { 2 });
The third version doesn't have any code, this version is for Player 3 with InterestGroup zero.

Then I connect to the same room and realize the test:
Player 1 and Player 2 can listen Player 3. (That's expected because everybody listen to zero)
Player 2 can listen to other Player 2. (That's expected)
Player 1 can listen to other Player 1. (That's expected)
Player 1 can listen to Player 2. (That's not expected because they belong to different interest groups)

I can't figure out how to solve this problem. After searching, I found this: https://forum.photonengine.com/discussion/14829/interest-group-does-nothing

There, @JohnTube said a line of code was missing but even adding that line the program doesn't have the expected test between interest groups. I don't know how to fix this or if @Slyp found a workaround. I can share my project if necessary.

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited December 2019
    Hi @Drakostar,

    Thank you for choosing Photon!

    Photon Voice 2 with PUN 2 integration has 2 clients: PUN client and Voice client.
    You are setting interest groups for the PUN client and expecting that to apply to the Voice client.
    This is not done out-of-the-box.

    To change interest groups for Voice client:

    PhotonVoiceNetwork.Instance.Client.SetInterestGroups

    or (not in PUN integration)

    VoiceConnection.Client.SetInterestGroups

    Also, do not forget to set the target interest group in Recorder.InterestGroup.
  • Hi again,

    I cannot fully understand your answer. According to Photon>Photon Voice>Demos>DemoVoicePun>DemoVoicePun-Scene I can see a Voice object with a Recorder and Photon Voice Network scripts.

    When I run in Editor mode the Voice object goes to DontDestroyOnLoad and I assume that is the Voice client. But, how and where I add PhotonVoiceNetwork.Instance.Client.SetInterestGroups?, when I use Photon.Voice.PUN.PhotonVoiceNetwork.Instance.Client everything is okay but when I try to add the last part ".SetInterestGroups" then compiler tells LoadBalancingTransport doesn't contain a definition for SetInterestGroups.

    Also, for the Recorder script I can see the InterestGroup attribute that is set to 0. by default. Should I set that value to another script or how? In the other post you said "using an interest group other than 0 means that you cannot receive your own events" and I am confused about how to set up the Interest Group in the Recorder because I don't want to do something that break audio.

    Thanks in advance and sorry for late response.

  • JohnTube
    JohnTube ✭✭✭✭✭

    Hi @Drakostar,


    Sorry for the confusion.

    I typed the name of the method from memory...

    The correct method to use is OpChangeGroups and not SetInterestGroups:

    PhotonVoiceNetwork.Instance.Client.OpChangeGroups

    Should I set that value to another script or how?

    The Recorder.InterestGroup is the target interest group used to transmit the outgoing voice stream.

    So for example if I have two players A and B that want to communicate in interest group X.

    I would do this from each client:

    PhotonVoiceNetwork.Instance.Client.OpChangeGroups(null, new byte[1] { X });
    recorder.InterestGroup = X;
    

    OR (since one group only is used AND the same group is used for incoming & outgoing):

    PhotonVoiceNetwork.Instance.Client.GlobalInterestGroup = X;
    

    OpChangeGroups call is used to define and set up interest groups to "listen to" or "receive from".

    Recorder.InterestGroup is used to define and set up interest groups to "talk to" or "transmit to".

    Of course this can be used in many ways.

    Players A and B could use different interest groups combinations.

    Each player could have different outgoing (talk to) & incoming (listen to) interest groups.

    Each player could listen to multiple groups and talk to a single group at a time per Recorder.

    In Photon Voice 1 we had this documented here. We will port this to Photon Voice 2 soon: naming is a bit different but API/concept is the same.

  • It worked,

    One interesting thing is that I can unsuscribe from channel zero with OpChangeGroups and that is excellent for private rooms. I just created a new script and just attached Voice Client as Recorder parameter and everything works. Then, put that script on client Player and ready.

    Thanks for the help, finally I got it.

  • JohnTube
    JohnTube ✭✭✭✭✭

    Hi @Drakostar,

    I can unsuscribe from channel zero with OpChangeGroups

    No you cannot unsusbcribe from interest group 0.

    You are probably just not transmitting anything to group 0 or no speaker is linked to any audio stream that is transmitting to group 0.