Unity Photon Pun 2 RPC Issue

51 Views Asked by At

I'm trying to use an RPC to tell all clients in a room to start the game. The RPC is called successfully on every client's game, but the photonView is always the master client's no matter which client it is run on.

I'm using this line to instantiate my player object:

GameObject newPlayer = PhotonNetwork.Instantiate(playerPrefab.name, Vector3.zero, Quaternion.identity);

Every player is instantiated with a PlayerController script on it. The master client instantiates an object over the network called NetworkManager that finds the master client in the start function using the following:

foreach (PlayerController playerController in FindObjectsOfType<PlayerController>()) {
 
       if (playerController.photonView.OwnerActorNr == PhotonNetwork.MasterClient.ActorNumber) {
 
            masterController = playerController;
 
       }
}

When the game is ready to start, I call the following RPC:

[PunRPC]
public void StartGameRPC() {
 
    if (photonView.IsMine) {
 
        //logic goes here
 
    }
}

The RPC is called using this line:

masterController.photonView.RPC("StartGameRPC", RpcTarget.All);

As I stated before, no matter which client the RPC is run on, the photonView is always the master client's. Its also possible that I am misunderstanding how RPCs work.

0

There are 0 best solutions below