Search Unity

Third Party PhotonNetwork.LoadLevel Goes back and forth on other clients

Discussion in 'Multiplayer' started by ANLevant, Mar 3, 2022.

  1. ANLevant

    ANLevant

    Joined:
    Jun 10, 2014
    Posts:
    28
    Hello!


    I have this issue: After lobby, when players are ready, the MasterClient uses

    Code (CSharp):
    1. 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:

    Code (CSharp):
    1. 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:


    Code (CSharp):
    1. var userIdToObjectIdMap = new Dictionary<string, MechaNetworkDTOListWrapper>();
    2.  
    3. foreach (Player player in PhotonNetwork.PlayerList)
    4. {
    5.    MechaNetworkDTOListWrapper mechaNetworkDtoListWrapper = new MechaNetworkDTOListWrapper();
    6.    userIdToObjectIdMap.Add(player.UserId, mechaNetworkDtoListWrapper);
    7. }
    8.  
    9. PhotonNetwork.CurrentRoom.CustomProperties.Add(USER_ID_TO_OBJECT_ID_MAP_FIELD_NAME,
    10.    JsonConvert.SerializeObject(userIdToObjectIdMap));
    11. PhotonNetwork.CurrentRoom.CustomProperties.Add(PLAYERS_ID_PLAYING_FIELD_NAME, "");
    12. PhotonNetwork.CurrentRoom.CustomProperties.Add(IS_SHOOTING_FIELD_NAME, false);
    13. PhotonNetwork.CurrentRoom.CustomProperties.Add(TIME_COUNTER_FIELD_NAME, 0f);
    14. PhotonNetwork.CurrentRoom.CustomProperties.Add(WINNER_PLAYER_FIELD_NAME, "");
    15. PhotonNetwork.CurrentRoom.CustomProperties.Add(CURRENT_PLAYER_TURN_INDEX_FIELD_NAME, -1);
    16.  
    17. PhotonNetwork.CurrentRoom.SetCustomProperties(PhotonNetwork.CurrentRoom.CustomProperties);
     
  2. maross334

    maross334

    Joined:
    Jul 28, 2021
    Posts:
    9
    CustomProperties is a read-only hashtable. I am not sure if there is anything else in your code generating the error, but you can't explicitly add anything to CustomProperties by invoking Add(). You should initialize a hashtable to pass to:
    Code (CSharp):
    1. PhotonNetwork.CurrentRoom.SetCustomProperties(PhotonNetwork.CurrentRoom.CustomProperties);
    Putting your network code in the Start method is good practice, but CustomProperties is a read-only property and might help solve it, or at least get you closer to the bug. An error log would help!

    Code (CSharp):
    1.         Hashtable props = new Hashtable();
    2.         props.Add(IS_SHOOTING_FIELD_NAME, false);
    3.         props.Add(TIME_COUNTER_FIELD_NAME, 0f);
    4.         props.Add(WINNER_PLAYER_FIELD_NAME, "");
    5.         PhotonNetwork.CurrentRoom.SetCustomProperties(props);
    Let me know if you get it to work :)