Looking for a simple working example of SyncListStruct

Everything I have tried has the client side object set to null. Other SyncList variables are working for me, just not SyncListStruct.

http://docs.unity3d.com/Manual/UNetStateSync.html

1 Like

@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()

there have been bugs in synclist, make sure you have latest patch release of editor.

1 Like

I’ve never used a Unity patch before. Can you please point me to info on how to patch?

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.

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.Operation.

======UPDATE’

I tried
voidBufChanged(SyncListStruct.Operationop, intitemIndex)
and it compiled.

You are supposed to update to 5.2.1f1, not 5.1.3f1.

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.

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
{

}

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);

3 Likes

@FStar
Thank you

For future new members, please use [ Code] tags. It will help with readability.

Will do, thanks for the tip :slight_smile:

How do you define “eqItem” that you are using to .add to your SyncListStruct

It’s an instance of the EquippedItem struct defined at the top.