Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Looking for a simple working example of SyncListStruct

Discussion in 'Multiplayer' started by Tinjaw, Sep 22, 2015.

  1. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    Everything I have tried has the client side object set to null. Other SyncList variables are working for me, just not SyncListStruct.
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  3. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    @seanr

    Thanks, I'll try that. I just noticed something weird. If I look at my script in the inspector, my SyncListStruct is missing. I added a copy (just appended 2 to it) and now the first SyncListStruct is showing and the second one isn't.

    And I am finding an odd, but apparently related, error in my console.

    IndexOutOfRangeException: Array index is out of range.
    UnityEditor.NetworkBehaviourInspector.OnInspectorGUI () (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Editor/NetworkBehaviourInspector.cs:122)
    UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean forceDirty, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect, Boolean eyeDropperDirty) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1162)
    UnityEditor.DockArea:OnGUI()
     
  4. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    there have been bugs in synclist, make sure you have latest patch release of editor.
     
    Tinjaw likes this.
  5. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I've never used a Unity patch before. Can you please point me to info on how to patch?
     
  6. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I think I properly patched Unity to 5.1.3p3. The issue remains with the IndexOutOfRangeException and one of the SyncListStruct not showing in the inspector.

    I'm going to try and take the example from the docs and modify it to see if I get the same issues.
     
  7. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I cannot get the example to work. First of all Operation is not defined. I can see SyncListInt.Operation or SyncListString.Operation. But no Operation, or SyncListStruct<T0>.Operation.

    ======UPDATE'

    I tried
    voidBufChanged(SyncListStruct<Buf>.Operationop, intitemIndex)
    and it compiled.
     
  8. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    You are supposed to update to 5.2.1f1, not 5.1.3f1.
     
  9. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
    I think I discovered my "problem". I saw this thread and then ran my host in the editor and my player standalone (instead of the other way around) and I found the same error as mentioned in the thread. So now I need to figure how to tell my program to use a specific channel when syncing my large object.
     
  10. FStar

    FStar

    Joined:
    Sep 11, 2015
    Posts:
    50
    Hi,

    below is a practical example from my code. The documentation for this was not exactly clear for me, but after some tries I came to understand it quite well.

    The code below works in 5.2.0f3:


    public struct EquippedItem
    {
    public long id;
    public ItemType type;
    public string name;
    public EquipmentSlot equipmentSlot;
    }

    public class SyncListEquippedItem : SyncListStruct<EquippedItem>
    {

    }


    public class PlayerInfo : NetworkBehaviour {

    [SyncVar]
    public string playerName;

    [SyncVar]
    public SyncListEquippedItem equippedItems = new SyncListEquippedItem();

    [SyncVar]
    public int health;
    }

    void Start() {
    _playerInfo.equippedItems.Callback = OnEquippedItemsChanged;
    }

    private void OnEquippedItemsChanged(SyncListEquippedItem.Operation op, int index){
    ...
    }

    some Cmd or other server side code;
    ..
    _playerInfo.equippedItems.Add(eqItem);

    ..

    _playerInfo.equippedItems.Remove(eqItem);
     
    VaporAnomaly, Kerosini and Zelek like this.
  11. Tinjaw

    Tinjaw

    Joined:
    Jan 9, 2014
    Posts:
    518
  12. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    For future new members, please use [ Code] tags. It will help with readability.

     
  13. FStar

    FStar

    Joined:
    Sep 11, 2015
    Posts:
    50
    Will do, thanks for the tip :)
     
  14. smitsc

    smitsc

    Joined:
    Mar 4, 2014
    Posts:
    4
    How do you define "eqItem" that you are using to .add to your SyncListStruct
     
  15. FStar

    FStar

    Joined:
    Sep 11, 2015
    Posts:
    50
    It's an instance of the EquippedItem struct defined at the top.