2

Edit: Changed arrays to be enabled into just objects for better readability.

Currently I'm using Photon and have a OnPlayerPropertiesChanged function calling an RPC in the player script to change the player's model. What model they have depends on the team that's stated in their custom properties. The two teams are "citizens" and "angels". I want the Citizen Model to show up when a person's team property is "citizen", and the same for property of "angel". Code snippets below:

GameManager:

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);
            }
        }

PlayerController:

[PunRPC]
        public void ChangeTeamObjs(PhotonHash changedProps)
        {
            switch (changedProps["team"].ToString())
            {
                    case specString:
                        citizenModel.SetActive(true);
                        angelModel.SetActive(false);
                        break;
                    case citiString:
                        citizenModel.SetActive(true);
                        angelModel.SetActive(false);
                        break;
                    case angelString:
                        citizenModel.SetActive(false);
                        angelModel.SetActive(true);
                        break;
                    default:
                        Debug.Log("ChangeTeamObjs() | Unknown team! | " + PhotonNetwork.LocalPlayer.NickName);
                        break;
            }
            ClientServerEnabling();
        }

Currently, each person's model changes correctly on their own screen, but both models on other players are enabled on local player's screens. How can I setup my code to have the other clients' models appear/disappear on a person's screen when the OnPlayerPropertiesUpdate() is called?

Jack Sebben
  • 69
  • 2
  • 9
  • not quiet sure what angelObs and PlayerObjs contain, but you set all playerObjs to true, if playerObjs contain the models then you have to make sure to set the opposing team model to false – nkazz Jan 06 '20 at 09:46
  • @nka_Zz Yeah, sorry about that. The angelObs (should be angelObjs*) and playerObjs are GameObject arrays. My code is slightly inconsistent (my fault), and in this case "players" and "citizens" are the same. So, depending on what custom property of ["team"] each person has (either spectator/citizen or angel), I want the objects in the arrays to be enabled/disabled. I have a switch case checking for the value. It should enable every object in the matching team's array, and disable object in the opposing team's array. Apologies in advance if you need more clarification, so please let me know. – Jack Sebben Jan 06 '20 at 14:58
  • You should put Debug.Log statements and see what gets called and what does not. Specifically, does GameManager.OnPlayerPropertiesUpdate get called? Does PlayerController.ChangeTeamObjs gets called with non-null changedProps? Also, why do you even need GameManager to call RPC's on other clients? The other clients should get GameManager.OnPlayerPropertiesUpdate callback when their properties update, right? So there is no need in RPC as far as I understand – Aleksandr Stepanov Jan 08 '20 at 02:02
  • @AleksandrStepanov Sorry I'm still relatively new to multiplayer API. The functions are running correctly. The models do change, but they only change for the local player. For example, if I wanted to change everybody's model at the same time, each local client's character would change. However, on each client's screen, the other players variables don't change (even if on the other players' local screens they do.) I know that's kind of confusing to explain, but I hope you understand. Also, if I don't use RPCs, how will I call ChangeTeamObjs from my GameManager? If need clarification, please ask – Jack Sebben Jan 08 '20 at 04:50
  • Can you see Debug.Log's on the other clients? – Aleksandr Stepanov Jan 10 '20 at 11:27

1 Answers1

2

I replied on your other questions (PUN Changes affect local players only, not other clients) with the similar issue, don't call rpc to a specific target, instead, set your rpc target to ALL:

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

halfer
  • 19,824
  • 17
  • 99
  • 186