RPC AllBuffered and OthersBuffered
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
RPC AllBuffered and OthersBuffered
dibset
2021-07-07 02:45:49
Hi, I have a problem and was wondering how i can fix this :
I have 3 players in a room. 1 master and 2 non-master.
Each player(non-master) has to ReadyUp. When each of the non master clicks on ReadyUp, the ReadyUp button for the becomes a "Waiting for other players" text (No more button). A "READY" text pops up on the player. Only when both non-master are ready can the masterclient click his "Deploy" button to the gamescene.
If the masterClient leaves the room, the masterClient is switched to 1 of the 2 non-master and for the new masterClient his "READY" fades and the text "Waiting for other players" becomes the "Deploy" button.
The problem is :
If i use AllBuffered or othersBuffered and the masterClient that left rejoins the same room, he won't be updated. He will still see the Ready text for both previously non-master players. Thus making it that if this non-master (previously masterClient) clicks on ReadyUp, he will see 3 "READY" players....which is not the reality.
Here is a piece of my code :
private void OnClickReady()
{
if(!PhotonNetwork.IsMasterClient)
{
this.photonView.RPC("RPCReadyState", RpcTarget.AllBuffered, PhotonNetwork.LocalPlayer);
readyButton.gameObject.SetActive(false);
waitingText.gameObject.SetActive(true);
}
else if(PhotonNetwork.IsMasterClient)
{
StartGame();
}
}
[PunRPC]
private void RPCReadyState(Player otherPlayer)
{
int index = spawnedPlayerList.FindIndex(x => x.playerNicknameNlevel.text == otherPlayer.NickName);
if (index != -1)
{
spawnedPlayerList[index].isReadyTxt.gameObject.SetActive(true);
spawnedPlayerList[index].isReady = true;
}
}
public void OnMasterSwitch()
{
if (PhotonNetwork.IsMasterClient)
{
spawnedPlayerList[0].isReady = false;
spawnedPlayerList[0].isReadyTxt.gameObject.SetActive(false);
readyButton.gameObject.SetActive(true);
waitingText.gameObject.SetActive(false);
}
}
Comments
if this non-master (previously masterClient) clicks on ReadyUp, he will see 3 "READY" players
Your code should probably only count the players who are active in the room and not count the Master Client (no matter who it is).
I would recommend using custom properties instead of buffered RPCs. You only want to sync a value per player and it should not change all that often. RPCs can be buffered more than once, posing a risk of filling the event buffer, which is hard to debug / notice.
The Asteroids Demo has a screen to show the ready state, if you are looking for inspiration.
Back to top