1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  4. Unity 2017.1 is now released.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

"Impossible" argument out of range error with SyncList

Discussion in 'Multiplayer Networking' started by Survivalist-Games, Jul 14, 2017 at 2:47 PM.

  1. Survivalist-Games


    Nov 24, 2014
    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):
    2. if (m_SyncedPlayers.Count > slot)
    3.     m_SyncedPlayers [slot] = player;
    m_SyncedPlayers is a SyncList implemented as follows:
    Code (CSharp):
    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.     }
    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. }
    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?

    Last edited: Jul 14, 2017 at 3:18 PM
  2. Zullar


    May 21, 2013
    What's count and what's slot? Is slot negative?