Search Unity

UNET Bug when modifying SyncListStructs before AddPlayerForConnection

Discussion in 'UNet' started by mischa2k, Jan 24, 2016.

  1. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I have a rather huge UNET project where a player has several different SyncListStructs for items, equipment, skills, quests etc. I implemented my own OnServerAddPlayer function, which:
    • Instantiates the playerPrefab
    • Then loads the player data from the Database and writes it to SyncLists
    • Then calls AddPlayerForConnection
    Writing to SyncLists before AddPlayerForConnection causes my last two SyncListStructs (skills and quest) to be not synced to a client anymore, while the first two work just fine. It can be seen in the Inspector here, where the last two SyncLists are empty on the client, even though they have values on the Server:
    2016-01-24.png

    Loading player data and writing to SyncLists after the AddPlayerForConnection call syncs them to clients properly though, but then OnStartLocalPlayer still doesn't have the loaded player data yet, which is a problem.

    Here is the client's log:
    2016-01-24(001).png

    And here is the server's log:
    2016-01-24(002).png

    Here is one of the SyncLists that act weird (I removed some functions for readability, but the values are the same) There are just 3 very basic values:
    Code (CSharp):
    1. [System.Serializable]
    2. public struct Skill {
    3.     public string name;
    4.     public bool learned;
    5.     public float lastCasted;
    6.  
    7.     public Skill(SkillTemplate template) {
    8.         name = template.name;
    9.         learned = template.learnDefault;
    10.         lastCasted = Time.time - (template.cooldown + template.castTime);
    11.     }
    12. }
    13.  
    14. public class SyncListSkill : SyncListStruct<Skill> { }
    15.  
    I load the player data by using the SyncList.Add function, so I am not really doing anything fancy here. I also tried to load the player data in another order, so that the two SyncLists that don't work are loaded first / last, but that makes no difference. I also tried to only load player data for the two SyncLists that don't work, but that doesn't change anything either.

    Also note that once they are messed up, adding something to them later (like accepting a quest) still won't sync that new quest to clients anymore.

    I use Unity 5.3.1f1 on Linux Mint and with the Reliable Fragmented channel. I tested it locally on the same computer.

    My project is pretty big, breaking it down into demo projects always takes a long time and seeing how my last two bug reports were ignored, I don't want to waste another day on that unless there is some interest here.
     
    Last edited: Jan 24, 2016
  2. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    Update: my workaround with adding SyncList data AFTER AddPlayerForConnection only works partially: the SyncLists are properly synced to the Client for the Client's own player, but they are not synced to the Client for a Client's surrounding players. This is really weird. Here is the exception that I get if a surrounding player's Script tries to access a SyncList:

    ArgumentOutOfRangeException: Argument is out of range.
    Parameter name: index
    at System.Collections.Generic.List`1[Skill].set_Item (Int32 index, Skill value) [0x0002b] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/List.cs:641
    at UnityEngine.Networking.SyncList`1[Skill].HandleMsg (UnityEngine.Networking.NetworkReader reader) [0x00095] in /home/builduser/buildslave/unity/build/Extensions/Networking/Runtime/SyncList.cs:370
    at Player.InvokeSyncListskills (UnityEngine.Networking.NetworkBehaviour obj, UnityEngine.Networking.NetworkReader reader) [0x00000] in <filename unknown>:0
    at UnityEngine.Networking.NetworkIdentity.HandleSyncList (Int32 cmdHash, UnityEngine.Networking.NetworkReader reader) [0x0012a] in /home/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:566
    at UnityEngine.Networking.ClientScene.OnSyncListMessage (UnityEngine.Networking.NetworkMessage netMsg) [0x00049] in /home/builduser/buildslave/unity/build/Extensions/Networking/Runtime/ClientScene.cs:766
    at UnityEngine.Networking.NetworkConnection.HandleReader (UnityEngine.Networking.NetworkReader reader, Int32 receivedSize, Int32 channelId) [0x0011f] in /home/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:430
    at UnityEngine.Networking.NetworkConnection.HandleBytes (System.Byte[] buffer, Int32 receivedSize, Int32 channelId) [0x00007] in /home/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:386
    at UnityEngine.Networking.NetworkConnection.TransportRecieve (System.Byte[] bytes, Int32 numBytes, Int32 channelId) [0x00000] in /home/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:536
    at UnityEngine.Networking.NetworkClient.Update () [0x0018c] in /home/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:648
    at UnityEngine.Networking.NetworkClient.UpdateClients () [0x00017] in /home/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkClient.cs:861
    at UnityEngine.Networking.NetworkIdentity.UNetStaticUpdate () [0x00005] in /home/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkIdentity.cs:1044

    (Filename: /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Collections.Generic/List.cs Line: 641)
     
  3. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347