LoadSceneAsync / Progress Bar

Options
Game log:
--- Join room
--- Ready up
--- When master clicks on start game only those who are ready can load into new scene.


By default, i use to load my scenes using:

private void OnPhotonCustomRoomPropertiesChanged(Hashtable roomProp)
{
// some removed code
if ((bool) roomProp[Constants.IS_PLAYING] && (bool) playersProps[Constants.IS_READY])
{
player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable {
{Constants.IS_PLAYING, true}
});

PhotonNetwork.LoadLevel(mapName.text)
}
}

private void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps)
{
// some removed code
if ((bool) roomProp.ContainsKey(Constants.IS_PLAYING))
{
if ((bool) roomProp[Constants.IS_PLAYING] && (bool) properties[Constants.IS_READY])
{
player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable {
{Constants.IS_PLAYING, true}
});
PhotonNetwork.LoadLevel(mapName.text)
}
}
}
But since i wanted a progress bar, i searched online but what i found wasnt all that helpfull since am new to Photon and generally know less about networking.
But i tried something like:

private void OnPhotonCustomRoomPropertiesChanged(Hashtable roomProp)
{
// some removed code
if ((bool) roomProp[Constants.IS_PLAYING] && (bool) playersProps[Constants.IS_READY])
{
player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable {
{Constants.IS_PLAYING, true}
});

StartCoroutine(LoadMap());
}
}

private void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps)
{
// some removed code
if ((bool) roomProp.ContainsKey(Constants.IS_PLAYING))
{
if ((bool) roomProp[Constants.IS_PLAYING] && (bool) properties[Constants.IS_READY])
{
player.SetCustomProperties(new ExitGames.Client.Photon.Hashtable {
{Constants.IS_PLAYING, true}
});
StartCoroutine(LoadMap());
}
}
}

public System.Collections.IEnumerator LoadMap()
{
loading.SetActive(true);
PhotonNetwork.isMessageQueueRunning = false;
AsyncOperation async = SceneManager.LoadSceneAsync("Scenes/Maps/" + mapName);
while (!async.isDone)
{
progressBar.value = async.progress;
yield return null;
}
}
But the problem with this is that unlike the first one, this dosnt alert "Ready"ed users to join room because of the isMessageQueueRunning
So am wondering if someone can guild me through on how to make all the "Read" user to see the loading scene. Am really stuck here thanks

Comments

  • Hi @chrys,

    you basically have two points where you want to load another scene. The first is the OnPhotonCustomRoomPropertiesChanged callback. When this one is called, you can check if a certain property is set and check afterwards, if your local client is ready to load another scene. The second one this like the first one, but the other way around: when your local client presses the 'ready' button, he checks if the certain room property is already set. If so he starts loading the new level, if not, he has to wait until OnPhotonCustomRoomPropertiesChanged gets called. You don't have to check OnPhotonPlayerPropertiesChanged in this case because you don't want to wait until everybody in the room is ready.

    If both requirements are true, the client can start loading the level async. Please make sure that you enable the MessageQueue after loading is completed. I'm currently not sure if you have to disable it at all.
  • chrys
    Options
    so its fine if i remove PhotonNetwork.isMessageQueueRunning = false;?
  • Depends on. If you have the MessageQueue running while the game is loading another scene, you still receive events and messages, that might be important for the game. In this case the client might be unable to process them correctly and he is losing required and important information. If you disable it, you won't have this scenario, but have to make sure, that you enable it again, after the scene has been loaded.