Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Third Party Photon PUN PlayerRoomIndexing

Discussion in 'Multiplayer' started by ThySpektre, Jun 1, 2019.

  1. ThySpektre

    ThySpektre

    Joined:
    Mar 15, 2016
    Posts:
    362
    This is a PUN Classic project. Using PUN 1.97

    I have a Empty GameObject in my scene called 'PlayerRoomIndexing' It contains the script found at Photon Unity Network>UtilityScripts>PhotonPlayer>PlayerRoomIndexing.

    I am getting the following error, twice upon creating a room.

    IndexOutOfRangeException: Index was outside the bounds of the array.
    ExitGames.UtilityScripts.PlayerRoomIndexing.RefreshData () (at Assets/AssetStorePackages/Photon Unity Networking/UtilityScripts/PhotonPlayer/PlayerRoomIndexing.cs:224)

    Tracing this back, I find it comes from this routine in PlayerRoomIndexing():

    Code (CSharp):
    1.         /// <summary>
    2.         /// Internal call Refresh the cached data and call the OnRoomIndexingChanged delegate.
    3.         /// </summary>
    4.         void RefreshData()
    5.         {
    6.             if (PhotonNetwork.room!=null)
    7.             {
    8.                 _playerIds = new int[PhotonNetwork.room.MaxPlayers];
    9.                 if (PhotonNetwork.room.CustomProperties.TryGetValue(PlayerRoomIndexing.RoomPlayerIndexedProp, out _indexes))
    10.                 {
    11.                     _indexesLUT = _indexes as Dictionary<int,int>;
    12.  
    13.                     foreach(KeyValuePair<int,int> _entry in _indexesLUT)
    14.                     {
    15.                         //Debug.Log("Entry; "+_entry.Key+":"+_entry.Value);
    16.                         _p = PhotonPlayer.Find(_entry.Key);
    17.                         _playerIds[_entry.Value] = _p.ID;
    18.                     }
    19.                 }
    20.             }else{
    21.                 _playerIds = new int[0];
    22.             }
    with this being the offending line:

    _playerIds[_entry.Value] = _p.ID;

    Any ideas Tobias?

    -----

    The whole traceback stack is probably helpful.

    IndexOutOfRangeException: Index was outside the bounds of the array.
    ExitGames.UtilityScripts.PlayerRoomIndexing.RefreshData () (at Assets/AssetStorePackages/Photon Unity Networking/UtilityScripts/PhotonPlayer/PlayerRoomIndexing.cs:224)
    ExitGames.UtilityScripts.PlayerRoomIndexing.OnPhotonCustomRoomPropertiesChanged (ExitGames.Client.Photon.Hashtable propertiesThatChanged) (at Assets/AssetStorePackages/Photon Unity Networking/UtilityScripts/PhotonPlayer/PlayerRoomIndexing.cs:143)
    UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
    NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[]) (at Assets/AssetStorePackages/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2854)
    Room:SetCustomProperties(Hashtable, Hashtable, Boolean) (at Assets/AssetStorePackages/Photon Unity Networking/Plugins/PhotonNetwork/Room.cs:320)
    ExitGames.UtilityScripts.PlayerRoomIndexing:AssignIndex(PhotonPlayer) (at Assets/AssetStorePackages/Photon Unity Networking/UtilityScripts/PhotonPlayer/PlayerRoomIndexing.cs:254)
    ExitGames.UtilityScripts.PlayerRoomIndexing:OnJoinedRoom() (at Assets/AssetStorePackages/Photon Unity Networking/UtilityScripts/PhotonPlayer/PlayerRoomIndexing.cs:111)
    UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
    NetworkingPeer:SendMonoMessage(PhotonNetworkingMessage, Object[]) (at Assets/AssetStorePackages/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2854)
    NetworkingPeer:OnEvent(EventData) (at Assets/AssetStorePackages/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:2562)
    ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(StreamBuffer)
    ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
    PhotonHandler:Update() (at Assets/AssetStorePackages/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:161)

    For this it appears that Setting a CustomRoomProperty before indexing is complete raises an error.

    Given the above, is it possible to set CustomRoomProperties at the time of creating a room without triggering this error? Should the errors just be ignored?
     
    Last edited: Jun 1, 2019