PhotonNetwork.SetMasterClient() not working
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).
PhotonNetwork.SetMasterClient() not working
fenyce_m
2021-03-21 17:28:57
Hello,
I am trying to understand why the Master Client doesn't switch when I call SetMasterClient.
I have two Android mobile devices. They run the same code apart from one bool variable which I use to distinguish between the two.
I tell one of the two to set itself as master client by doing a check on that bool variable but although SetMasterClient returns true, the network doesn't acknowledge the switch
if (_Kwesi != null)
{
bool _success = PhotonNetwork.SetMasterClient(PhotonNetwork.LocalPlayer);
Debug.LogWarning($"Local player Nickname: {PhotonNetwork.LocalPlayer.NickName}, Actor Number: {PhotonNetwork.LocalPlayer.ActorNumber}, IsMasyer: {PhotonNetwork.LocalPlayer.IsMasterClient}, UserID: {PhotonNetwork.LocalPlayer.UserId}");
if (_success)
{
Debug.Log($"I have assigned the master client to the !autoconnect player. Outcome: {_success}");
Debug.Log($"AM I THE MASTER CLIENT? = {PhotonNetwork.IsMasterClient}"); //THIS ALWAYS RETURNS FALSE even if it should have switched
}
}
else
{
Debug.LogError("Failed to assign master client to Kwesi");
}
}
I also tried to turn this into an RPC which I call on the master client from another client as I thought maybe only the master client can force a mnual switch but the result doesn't change.
What am I doing wrong?
Many thanks!
Comments
I found out what the problem was, I wasn't waiting enough time for the master client to switch. Implementing the OnMasterClientSwitched callback clarified when the event occurred. I found this youtube clip helpful https://www.youtube.com/watch?v=yrB7Hyh2BE4&ab_channel=FirstGearGames
Back to top