0

I've been having some issues with how other clients behave in a player's game. Basically, if there's a change that affects every client, it will work. However, it will only show up correctly on the local player's screen. Other players (as they appear on a client's screen) remain unchanged.

For example, let's say I have a boolean called "test" set to false. Every player in the room at the same time is meant to turn this boolean to true. Each player's own character gets "test" set to true, but other clients on a local player's screen show their boolean as false.

Example of how I go through every player below:

foreach (var item in PhotonNetwork.PlayerList)
            {
                var itemPhotonView = (PhotonView)item.TagObject;

                itemPhotonView.RPC("SetPlayerTeam", item, citiString);
            }

I want the code above to go through every character, even if not a local player. I believe it accomplishes it, but I'm not 100% sure.

public override void OnPlayerPropertiesUpdate(Player target, ExitGames.Client.Photon.Hashtable changedProps)
        {
            if (changedProps.ContainsKey("team"))
            {
                var targetPhotonView = (PhotonView)target.TagObject;
                targetPhotonView.RPC("ChangeTeamObjs", target, changedProps);
            }

        }

The code above I know for sure does not change non-local clients. I'm unsure if I should use the 'foreach' method like the first example because I'm not even sure if that will accomplish it. Any ideas?

Jack Sebben
  • 69
  • 2
  • 9

1 Answers1

1

Sending rpc to all can be done in a more efficient way, by defining the target of the rpc to be everyone, this will prevent overloading the network traffic, and only one rpc is sent.

https://doc.photonengine.com/en-us/pun/v2/gameplay/rpcsandraiseevent#targets__buffering_and_order

PhotonView photonView = PhotonView.Get(this);
photonView.RPC("ChangeTeamObjs", RpcTarget.All, , item, citiString);
halfer
  • 19,824
  • 17
  • 99
  • 186
  • Most of these RPCs are called from a GameManager type script. The ones I could change to "PhotonView.Get(this);" I did. Same with for "RpcTarget.All". Now, the code seems to be running irrationally. Everyone is supposed to be set to 'citizen', and one person set to 'angel'. Instead, everybody's team is set to angel. Only one person's model changes to the angel model, though. Plus, the other two angels with citizen models have nothing except for their speed changed. Only local players were affected, now it seems to be all players. **If you want me to add more post comments with my code I can.** – Jack Sebben Jan 09 '20 at 06:21
  • Never mind, after fixing other parts of my spaghetti code it turns that RpcTarget.All does fix the problem. Thank you! – Jack Sebben Jan 14 '20 at 16:35