Important Issue Need Help! | Properly loading new level with async operation
Options
Hey guys,
We are building a 1 v 1 fast paced action mobile game.
But while we are testing the game we found out an issue. Before loading new scene we are setting PhotonPlayer team property. First thing im doing at new scene instantiating player depending on their teams. Some times (usually when trying to rematchmaking) team property not syncing at that moment.
I know PhotonNetwork.LoadLevel, automaticallySyncScene right thing to do. But we got a loading scene and we are using SceneManager.LoadSceneAsync.
I made up a solution like this. But i think this is not right solutiton.
So any advice would be appreciated.
Have a nice work.
We are building a 1 v 1 fast paced action mobile game.
But while we are testing the game we found out an issue. Before loading new scene we are setting PhotonPlayer team property. First thing im doing at new scene instantiating player depending on their teams. Some times (usually when trying to rematchmaking) team property not syncing at that moment.
I know PhotonNetwork.LoadLevel, automaticallySyncScene right thing to do. But we got a loading scene and we are using SceneManager.LoadSceneAsync.
I made up a solution like this. But i think this is not right solutiton.
bool isReady;
void OnPhotonPlayerPropertiesChanged(object[] props)
{
bool tempBool = true;
foreach (var item in PhotonNetwork.playerList)
{
if (item.GetTeam() == PunTeams.Team.none)
{
tempBool = false;
break;
}
}
isReady = tempBool;
}
void OnPhotonPlayerPropertiesChanged(object[] props)
{
bool tempBool = true;
foreach (var item in PhotonNetwork.playerList)
{
if (item.GetTeam() == PunTeams.Team.none)
{
tempBool = false;
break;
}
}
isReady = tempBool;
}
IEnumerator IeAsyncLoad(AsyncOperation async)
{
yield return new WaitUntil(() => async.progress >= 0.9f && isReady);
if (!PhotonNetwork.isMasterClient)
this.photonView.RPC("Message", PhotonTargets.Others, PUNMessages.synLoadLevel);
}
{
yield return new WaitUntil(() => async.progress >= 0.9f && isReady);
if (!PhotonNetwork.isMasterClient)
this.photonView.RPC("Message", PhotonTargets.Others, PUNMessages.synLoadLevel);
}
So any advice would be appreciated.
Have a nice work.
0
Comments
-
Hi @TetraGames,Before loading new scene we are setting PhotonPlayer team property.
You can try addingPhotonNetwork.SendOutgoingCommands();
after setting the Player Properties and before calling PhotonNetwork.LoadLevel(). This way you make sure that the message is sent before the next scene is gets loaded. Loading a scene stops the message queue and starts it again after the scene has been loaded. In between no messages are sent and furthermore the updated Player Properties might not be available on all clients immediately after the new scene has been loaded.1 -
Thanks for your answer. I solved this by setting PhotonPlayer propertiesChristian_Simon said:Hi @TetraGames,
Before loading new scene we are setting PhotonPlayer team property.
You can try addingPhotonNetwork.SendOutgoingCommands();
after setting the Player Properties and before calling PhotonNetwork.LoadLevel(). This way you make sure that the message is sent before the next scene is gets loaded. Loading a scene stops the message queue and starts it again after the scene has been loaded. In between no messages are sent and furthermore the updated Player Properties might not be available on all clients immediately after the new scene has been loaded.
before joining or creating room. MasterClient is always is blue and other one always red.0