O'Reilly logo

Unity Multiplayer Games by Alan Stagner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required