The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

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

Write Us
an E-Mail

Feel free to send your question directly to our developers.

LoadLevel or LoadLevelAsync

dyawitz
2018-06-18 18:37:15

I'm trying to find the best way to trigger scene loading for our multiplayer VR game. The master client will initiate the game from the menu scene and all players should then move to the game scene. Is it recommended to use the new LoadLevelAsync or the original LoadLevel? When I tried LoadLevel, everyone's screen froze while the scene loaded which I want to avoid. Ideally, the master client would somehow tell all the other clients to load the scene in the background and then all clients enter when everyone is loaded. Is this possible with LoadLevelAsync? Thanks.

Comments

dyawitz
2018-06-18 19:01:43

I have not tried putting either LoadLevel or LoadLevel Async in a coroutine but I now see some examples of that posted. I'm wondering if that would help the freezing issue - e.g., using regular LoadLevel with AutomaticallySyncScene = true or LoadLevelAsync in a coroutine.

[Deleted User]
2018-06-21 10:05:40

Hi @dyawitz,

Ideally, the master client would somehow tell all the other clients to load the scene in the background and then all clients enter when everyone is loaded. Is this possible with LoadLevelAsync?

This is possible. If you have enabled PhotonNetwork.automaticallySyncScene and the MasterClient loads another scene by using PhotonNetwork.LoadLevelAsync. This way each client will load the next scene. After loading a certain scene each client can set a Custom Player Property which gets automatically synchronized across all clients and let each other client know, that this certain client has finished loading the level. The MasterClient can also use this information, to check regularly, if each client is ready. If each client has finished loading the level, the MasterClient can for example raise an event by using PhotonNetwork.RaiseEvent to tell the other client what to do next.

dyawitz
2018-06-21 14:54:20

Thanks Christian, this is helpful. A few follow up questions:

  1. Does PhotonNetwork.automaticallySyncScene need to be set separately by each player or is it sufficient for the master client to set this for everyone? Does it matter when it gets set relative to connecting to the master server, joining a room, etc?

  2. Once the MC calls LoadLevelAsync, what's a good way to check that the level is loaded? Is there a callback?

  3. Lastly, I'm not totally clear on the difference between loading the scene and actually moving to the new scene. From your comment it sounds like they are separate. I can have the MC trigger the loading for each client, have each client respond that their loading is complete (with custom props), and then when the MC sees everyone is ready, raise an event to tell all clients to move. But how do I do that last step of moving to the new scene that is already loaded but not the active scene?

Sorry if these are very basic questions! Thanks for your help.

dyawitz
2018-06-21 15:45:13

To clarify on #2, I am asking for the best way to check at the client level - not the master client. How can I check for the other clients that they have successfully received the load command from the MC and that it's finished.

[Deleted User]
2018-06-26 08:56:44

1) Does PhotonNetwork.automaticallySyncScene need to be set separately by each player or is it sufficient for the master client to set this for everyone? Does it matter when it gets set relative to connecting to the master server, joining a room, etc?

Each client have to set this option individually. You can basically set this option whenever you want to, either before connecting or before joining the room. It might also work when you change this option after joining the room. If your game depends on this feature, I would recommend setting it before joining the room.

If this option is enabled, the synchronized level will be automatically loaded by the client as soon as he has joined the room or the MasterClient loads another level.

2) Once the MC calls LoadLevelAsync, what's a good way to check that the level is loaded? Is there a callback?

To clarify on #2, I am asking for the best way to check at the client level - not the master client. How can I check for the other clients that they have successfully received the load command from the MC and that it's finished.

They will definitely receive this, because the synchronized level information is stored within the Custom Room Properties, which are always synchronized on all clients who are connected to the room. If you want to have more control over it or make other modifications to the existing system, you can either modify the source code or - the better approach in this case - implement a similar solution on your own which also uses the Custom Room Properties and the void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged) callback.

3) [...] But how do I do that last step of moving to the new scene that is already loaded but not the active scene?

After loading the level synchronized, a client can set a Custom Player Property to notify each other client, that he has finished loading the level. The local client can do this by using PhotonNetwork.player.SetCustomProperties(...). This changes gets synchronized on all clients in the room and void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps) will be called on each client. The MasterClient can use this callback, to iterate through all clients' properties and check, if all clients are ready. If a certain client is not ready, you can skip the rest until the callback gets called again. You would have to do this until all clients are ready. If so, you can for example raise an event for all clients telling them that they can begin moving now. Therefore you would have to block movement input somehow and unblock it after receiving a certain game event.

dyawitz
2018-06-29 15:17:25

Christian, thank you for this explanation but I have to say this seems so complicated. Is this the approach Photon recommends to loading new scenes in a multiplayer VR game or am I making this unnecessarily complicated?

[Deleted User]
2018-07-03 13:23:25

This is probably the best way to get notified, which client has finished loading the new scene.

Back to top