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

"Impossible" argument out of range error with SyncList

Discussion in 'Multiplayer' started by YondernautsGames, Jul 14, 2017.

  1. YondernautsGames

    YondernautsGames

    Joined:
    Nov 24, 2014
    Posts:
    352
    Hey all. Does anyone know how the following can possibly happen?

    I have a function with the following code in it (called on the server):
    Code (CSharp):
    1.  
    2. if (m_SyncedPlayers.Count > slot)
    3.     m_SyncedPlayers [slot] = player;
    4.  
    m_SyncedPlayers is a SyncList implemented as follows:
    Code (CSharp):
    1.  
    2. public class SyncListPlayer : SyncList<BaseMpPlayer>
    3. {
    4.     protected override void SerializeItem (NetworkWriter writer, BaseMpPlayer player)
    5.     {
    6.         if (player != null)
    7.             writer.Write (player.gameObject);
    8.         else
    9.             writer.Write ((GameObject)null);
    10.     }
    11.  
    12.     protected override BaseMpPlayer DeserializeItem (NetworkReader reader)
    13.     {
    14.         GameObject obj = reader.ReadGameObject ();
    15.         if (obj != null)
    16.             return obj.GetComponent<BaseMpPlayer> ();
    17.         else
    18.             return null;
    19.     }
    20. }
    21.  
    However, if I run in the editor as a client, connecting to a separate instance that's hosting then I get the following error:
    I've only just started using this, so that is the only place a value is assigned and if I comment out those 2 lines then no error is thrown. I'm guessing that since the error is thrown on the client it's something to do with the sync. I do have a sync handler callback attached (set in OnStartClient), but even if it is empty it still throws the error.

    I'm not sure where to start with this. It doesn't seem possible since I explicitly check the size before assigning the value. Any clues?

    Thanks
     
    Last edited: Jul 14, 2017
  2. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    What's count and what's slot? Is slot negative?