Syncing a level between players
In Unity Networking, we had to develop our own way to make sure each player was running on the same level, via RPCs, disabling the network queue, waiting for the load to finish, and so on.
In Photon, this problem is significantly easier to solve. You simply set PhotonNetwork.automaticallySyncScene
to true, and to load a level call PhotonNetwork.LoadLevel
on the master client. For example, we can modify our lobby example to automatically sync the scene between players in a room.
Firstly, in Start
we would enable automatic level syncing:
void Start() { // ... // ensure that all players play on the same map PhotonNetwork.automaticallySyncScene = true; }
Then, when starting a game, we use PhotonNetwork's load level replacement in order to load the level for all players:
void OnCreatedRoom() { PhotonNetwork.LoadLevel( "Level Name Here" ); }
Note that level loads can also occur in-game. For example, this feature makes it incredibly easy to add a map vote feature...