Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  3. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

"Impossible" argument out of range error with SyncList

Discussion in 'Multiplayer Networking' started by Survivalist-Games, Jul 14, 2017.

  1. Survivalist-Games

    Survivalist-Games

    Joined:
    Nov 24, 2014
    Posts:
    49
    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:
    488
    What's count and what's slot? Is slot negative?