I'm trying to understand what exactly is Photon Networking Master Client. Docs give the folowing usage scenario for this term:
In absence of a server, it can be made responsible for handling logic that should only be executed by one client in a room (e.g. starting a match when everyone is ready).
Why would I want to delegate some server functionality to one of the clients? Isn't Photon Server supposed to be always available?
For example, in this Photon tutorial they use quote "very convenient feature":
PhotonNetwork.automaticallySyncScene = true
When this is true, the MasterClient can call PhotonNetwork.LoadLevel() and all connected players will automatically load that same level.
Why give one of the clients priviliges to sync everybody, if they have Photon server for that?
To sum up I have 2 questions:
1) What exactly is a master client?
2) What are some typical usage scenarios?
Thank you very much!
Photon server can do a little in fact. Basically it only helps clients to exchange with messages.
Since server can't run game logic, you have 2 options, either run game logic in parallel on all clients or choose one client who does all calculations and sends resulting game state to all other clients. With such authoritative client, it's much easier to keep all clients in-sync.
You should not care much about which client is the master. It's assigned automatically. If current master disconnects, next client in a room takes over. You still can switch master client manually if required.
When implementing game logic, use PhotonNetwork.isMasterClient property to check if current client is a master. If you want to trigger some action from non-master client, simply send RPC to a master asking it to do an action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With