Search Unity

Third Party Photon -- send RPC to specific groups/PhotonView

Discussion in 'Multiplayer' started by jtsmith1287, Sep 9, 2014.

  1. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    So I've got several objects that sync with a photonview. Players each have one and every AI object has one. Lots of the RPCs are similar and there's a lot of shared code, so I haven't run into this problem yet. I'm sending every operation to the master client for authority and then master client updates all other clients. This means the Master client (which is a on a server and not run by a player) has RPCs the clients don't. This of courses raises an error stating that other photonviews on the master dont have the RPC I'm calling.

    So I know photon has groups for each photon view, but the documentation doesn't explain its functionality. I'm not sure if this is what I want, but I'd love to put master on like group 99 or something to call RPCs just on that. However I can't for the life of me figure out how to call to a specific group. I can set groups all day, but that obviously doesn't help me much, haha. Thanks in advance for the help.
     
  2. vadiml

    vadiml

    Joined:
    Aug 12, 2014
    Posts:
    32
    You can specify master client as target in RPC call:
    RPC("methodName", PhotonTargets.MasterClient);
     
  3. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
    Each PhotonView can be assigned to a Group. If you use an RPC, that is done per PhotonView and this defines the Group.
    Each client needs to tell Photon which Groups it wants to get updates for. By default, all Groups are ignored. Group 0 is an exception and everyone always gets this Group's events.

    You should keep in mind that you might get into trouble when the Master Client leaves. In worst case, you need to end the game then, because no one else got any of the updates that target the Master Client. This is especially true when the current Master Client times out (when the client crashed or got in the background in iOS) as there are several seconds before the server detects the Master Client to be gone.
     
  4. jtsmith1287

    jtsmith1287

    Joined:
    Aug 3, 2014
    Posts:
    787
    Oh dumb. That's too easy, haha. Thanks.
     
  5. Chella90

    Chella90

    Joined:
    Sep 11, 2014
    Posts:
    8
    I think u can use PhotonPlayer.Find(ownerId) as target in RPC..
     
  6. ctalmeida

    ctalmeida

    Joined:
    Sep 3, 2014
    Posts:
    13
    Hi Tobiass

    Look for implementing interest management using photonview group number.

    What is the limit of the group number? I am looking on a map that may have 2,500 areas.

    I just did a test, created 2 players with group zero on the instantiate,

    PhotonNetwork.Instantiate("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);

    then sent RPC on both and worked fine, then I changed player number 2 photonview group to 1. Player with group = 0 send RPCs but the player 2 does not get the message. You said above that group 0 always send messages to all. Is that correct?

    Is there any place with documentation of photonview groups?

    Thanks

    Carlos
     
    Last edited: Dec 17, 2014
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
    @ctalmeida:
    You won't be able to do 2500 areas. 255 is the max and actually group 0 is already taken and going to everyone.
    I assume you instantiate in Group 0 but the RPC goes to 1 or 2?

    All Instantiate calls are internally in Group 0 and get sent to everyone "live" and to new players when they join. All Instantiates for GameObjects that are still alive when you join. The clients will then comb through the messages and disregard those that are not in groups that are of interest at that time.
    This means: a) you will not know instantiated game objects that were in a group you didn't see when you joined and b) too many "instantiates" might break a client when it joins.

    This stuff is good to reduce messages/sec in a small-ish game but you can't realize MMO games with it. That's not the intention.
     
  8. J_Troher

    J_Troher

    Joined:
    Dec 2, 2013
    Posts:
    42
    How do you tell your RPC's which group to go to?

    I can instantiate my prefabs into different groups, and I believe I am changing their sending and receiving properly.. But I get RPC Errors on clients that are in different groups, saying called by Remote PV, Ignored.
     
  9. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
    The "ignored" log tells you that an RPC was not executed because it does not match the group of your instance of the PhotonView. This is likely due to changing the Group of a PhotonView locally. That is not synced at the moment.
     
  10. J_Troher

    J_Troher

    Joined:
    Dec 2, 2013
    Posts:
    42
    Very Good Very Good! I came up with a very nice way to do what I wanted to Accomplish. I hope its as clean as it appears to me anyway.

    I wrote a group Manager, that stays in group 0 (with the master), When somebody joins the room and spawns for the first time, they are spawned in Group 0. Then immediately switched to the "default group", in my case I just chose group 1. why not? Which leave's group 0 that the manager and master are running on open to send/receive the buffered RPCs when somebody new connects. This also ensures that your spawned prefab exists No matter What. ( the problem i was running into ).
    Their Prefab is then added to a list by means of a Buffered RPC.

    Then, every prefab tell's said group manager what group they are in, as well as any PV's that may be connected to them.
    This is done every so often, as well as forced whenever you do change group.

    Now on the client side of the group manager, if the update you receive from the master does not match the name of the prefab in the list's PV.group id, then it simply turns off the gameobject. And of course, if the update you receive matches whats in your list, then it disregards and you go about your business.

    Then it was simply the matter of enabling Sending/Receiving of the group it enters, and turning off the group you're leaving.
    Which I do check to make sure the group you're leaving is not 0, since I need that open for the master and group to talk to everybody at once. This is also where I keep my chat component for the room.

    I may post the script i wrote here at some point. I quite like it and it seems to work very well for what I'm doing. I'm not using alot of groups, but I read one of your replies somewhere on here that photon allows 255 groups in a room? That is way more than I would ever possibly need, but I'm pretty sure this does it good and would handle it all very well.

    Hopefully this little novel I wrote will help anyone else that wants to do something with instantiation groups :)
     
  11. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    Hi,
    So here is my issue....

    It is a golf game. My player has a club, he swings and hits the ball. Upon doing so, I want to hide the club. This works on a local level, but the network reflection of said club, remains seen. I understand why. I do not understand how to hide it tho since any call to group "club", will hide all clubs.

    I want to target only the single object that is the network equivalent of this object, I want to hide its "reflection".


    HOW????!
     
  12. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
    If you synchronize "i am swinging" and every client is showing that swing, why don't you make all clients hide the club "on swing"? You don't have to sync "hide club, because im swining it" in the first place.
     
  13. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699
    I need to access just the reflection agent.


    So, I have a club. My opponent has a club. I swing my club, my opponent does not.

    That's why I need to access just the single "reflection", mirror object over the network.

    I am thinking I will pass position and rotation values to match.
     
  14. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,699

    Solved.
    Just forgot to add scale to my custom NetworkCharacter.
     
  15. GameTrackStudio

    GameTrackStudio

    Joined:
    Mar 31, 2020
    Posts:
    3