PhotonNetwork.LoadLevel Scene not loaded Goes back and forth on other clients
Hello!
I have this issue: After lobby, when players are ready, the MasterClient uses
PhotonNetwork.LoadLevel("IngameScene")
To move to the next scenne.
Clients other than Master initially switch to the scene, then go back to the lobby for some reason. Any idea of what can be happening?
This configuration is on:
PhotonNetwork.AutomaticallySyncScene = true;
Update
After debugging my code line by line, this error is being caused by the custom properties I'm writting during the Awake method. I moved them to the Start method but the error persists.
Here is my custom properties for this scene:
var userIdToObjectIdMap = new Dictionary<string, MechaNetworkDTOListWrapper>(); foreach (Player player in PhotonNetwork.PlayerList) { MechaNetworkDTOListWrapper mechaNetworkDtoListWrapper = new MechaNetworkDTOListWrapper(); userIdToObjectIdMap.Add(player.UserId, mechaNetworkDtoListWrapper); } PhotonNetwork.CurrentRoom.CustomProperties.Add(USER_ID_TO_OBJECT_ID_MAP_FIELD_NAME, JsonConvert.SerializeObject(userIdToObjectIdMap)); PhotonNetwork.CurrentRoom.CustomProperties.Add(PLAYERS_ID_PLAYING_FIELD_NAME, ""); PhotonNetwork.CurrentRoom.CustomProperties.Add(IS_SHOOTING_FIELD_NAME, false); PhotonNetwork.CurrentRoom.CustomProperties.Add(TIME_COUNTER_FIELD_NAME, 0f); PhotonNetwork.CurrentRoom.CustomProperties.Add(WINNER_PLAYER_FIELD_NAME, ""); PhotonNetwork.CurrentRoom.CustomProperties.Add(CURRENT_PLAYER_TURN_INDEX_FIELD_NAME, -1); PhotonNetwork.CurrentRoom.SetCustomProperties(PhotonNetwork.CurrentRoom.CustomProperties);
Best Answer
-
After trying my best with this issue. In the end I just went ahead with working around it. Seem slike aPhoton bug.
After setting the room properties, if you try to modify them after switching scene, it will fail without showing any errors and unload the scene.
My work-around was using PunRPC or Player's CustomProperties instead of Room CustomProperties.
0
Answers
-
Uptade 2:
I've found that what causes the problem is copying a reference to the same CustomProperties table that was user before
PhotonNetwork.CurrentRoom.SetCustomProperties(PhotonNetwork.CurrentRoom.CustomProperties);
Instead of creating a new one before passing it as a reference and addint it later
Hashtable customProperties = new Hashtable(); ... PhotonNetwork.CurrentRoom.SetCustomProperties(customProperties);
Still, ther eis no mechanism to safely copy the properties that are still on the room out of the box. I will try some solutions and come back with an answer
0 -
Never modify
PhotonNetwork.CurrentRoom.CustomProperties
directly. Create a new Hashtable, add the new or changed keys with their values and then callPhotonNetwork.CurrentRoom.SetCustomProperties
.You may want to set those values when the Master Client created the room (there is a callback for that).
As you set all properties (even those pre-existing), the clients will likely load the scene that is indicated in via the properties. This will be solved when you only set new / modified props with a separate Hashtable.
0 -
After trying my best with this issue. In the end I just went ahead with working around it. Seem slike aPhoton bug.
After setting the room properties, if you try to modify them after switching scene, it will fail without showing any errors and unload the scene.
My work-around was using PunRPC or Player's CustomProperties instead of Room CustomProperties.
0 -
This is the first report of such an issue in years. I'm happy you have a workaround but if this is a bug in PUN 2, it's kind of rare.
As said: Don't modify the custom properties Hashtable directly.
0